Skip to content

Commit e84313f

Browse files
committed
[SERVER] Speed up replication
Handling block replies on uplink connections is now parallelized: - write to disk - relay data to clients - request next chunk (when BGR is active) happens in parallel now.
1 parent 4a4c8c5 commit e84313f

4 files changed

Lines changed: 233 additions & 173 deletions

File tree

src/server/globals.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ struct _dnbd3_uplink
9292
pthread_t thread; // thread holding the connection
9393
pthread_mutex_t sendMutex; // For locking socket while sending
9494
pthread_mutex_t queueLock; // lock for synchronization on request queue etc.
95+
pthread_mutex_t asyncHandleMutex; // async handling of received reply
96+
pthread_cond_t asyncHandleCond; // condition for async receive handler
9597
dnbd3_image_t *image; // image that this uplink is used for; do not call get/release for this pointer
9698
pthread_mutex_t rttLock; // When accessing rttTestResult, betterFd or betterServer
9799
atomic_int rttTestResult; // RTT_*
@@ -105,7 +107,7 @@ struct _dnbd3_uplink
105107
// If BGR == BGR_HASHBLOCK, -1 means "currently no incomplete block"
106108
atomic_uint_fast64_t bytesReceived; // Number of bytes received by the uplink since startup.
107109
atomic_uint_fast64_t bytesReceivedLastSave; // Number of bytes received when we last saved the cache map
108-
int queueLen; // length of queue
110+
int queueLen; // length of queue (slots; either BGR (no client at all) or one or more clients)
109111
int idleTime; // How many seconds the uplink was idle (apart from keep-alives)
110112
dnbd3_queue_entry_t *queue;
111113
atomic_uint_fast32_t queueId;
@@ -169,15 +171,15 @@ struct _dnbd3_client
169171
{
170172
#define HOSTNAMELEN (48)
171173
atomic_uint_fast64_t bytesSent; // Byte counter for this client.
172-
dnbd3_image_t * _Atomic image; // Image in use by this client, or NULL during handshake
174+
_Atomic(dnbd3_image_t *) image; // Image in use by this client, or NULL during handshake
175+
pthread_t thread;
173176
int sock;
174-
_Atomic uint8_t relayedCount; // How many requests are in-flight to the uplink server
177+
_Atomic(uint8_t) relayedCount; // How many requests are in-flight to the uplink server
175178
bool isServer; // true if a server in proxy mode, false if real client
176179
dnbd3_host_t host;
177180
char hostName[HOSTNAMELEN]; // inet_ntop version of host
178181
pthread_mutex_t sendMutex; // Held while writing to sock if image is incomplete (since uplink uses socket too)
179182
pthread_mutex_t lock;
180-
pthread_t thread;
181183
};
182184

183185
// #######################################################

src/server/locks.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define LOCK_IMAGE_LIST 150
1919
#define LOCK_IMAGE 160
2020
#define LOCK_UPLINK_QUEUE 170
21+
#define LOCK_UPLINK_ASYNC_HANDLE 175
2122
#define LOCK_ALT_SERVER_LIST 180
2223
#define LOCK_CLIENT_SEND 190
2324
#define LOCK_UPLINK_RTT 200

src/server/net.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -680,15 +680,9 @@ static dnbd3_client_t* freeClientStruct(dnbd3_client_t *client)
680680
}
681681
ref_put( &uplink->reference );
682682
}
683-
if ( client->relayedCount != 0 ) {
683+
while ( client->relayedCount != 0 ) {
684684
logadd( LOG_DEBUG1, "Client has relayedCount == %"PRIu8" on disconnect..", client->relayedCount );
685-
int i;
686-
for ( i = 0; i < 1000 && client->relayedCount != 0; ++i ) {
687-
usleep( 10000 );
688-
}
689-
if ( client->relayedCount != 0 ) {
690-
logadd( LOG_WARNING, "Client relayedCount still %"PRIu8" after sleeping!", client->relayedCount );
691-
}
685+
sleep( 1 );
692686
}
693687
}
694688
mutex_lock( &client->sendMutex );
@@ -748,4 +742,3 @@ static void uplinkCallback(void *data, uint64_t handle, uint64_t start UNUSED, u
748742
mutex_unlock( &client->sendMutex );
749743
client->relayedCount--;
750744
}
751-

0 commit comments

Comments
 (0)