summaryrefslogtreecommitdiffstats
path: root/src/server/uplink.c
diff options
context:
space:
mode:
authorSimon Rettberg2017-10-25 15:32:02 +0200
committerSimon Rettberg2017-10-25 15:32:02 +0200
commita812c8ea51834482fcf1bc58a147a37886f58285 (patch)
tree2516df9af960b0a2572e287b66c6270b9a37c6dd /src/server/uplink.c
parent[SERVER] Improve altserver handling and selection (diff)
downloaddnbd3-a812c8ea51834482fcf1bc58a147a37886f58285.tar.gz
dnbd3-a812c8ea51834482fcf1bc58a147a37886f58285.tar.xz
dnbd3-a812c8ea51834482fcf1bc58a147a37886f58285.zip
[SERVER] Improve handling of byte stats counters
Less writes to variables, more up-to-date values for uplinks.
Diffstat (limited to 'src/server/uplink.c')
-rw-r--r--src/server/uplink.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/server/uplink.c b/src/server/uplink.c
index e899ed9..2f71a4c 100644
--- a/src/server/uplink.c
+++ b/src/server/uplink.c
@@ -23,6 +23,7 @@ static void uplink_handleReceive(dnbd3_connection_t *link);
static int uplink_sendKeepalive(const int fd);
static void uplink_addCrc32(dnbd3_connection_t *uplink);
static void uplink_sendReplicationRequest(dnbd3_connection_t *link);
+static void uplink_updateGlobalReceivedCounter(dnbd3_connection_t *link);
// ############ uplink connection handling
@@ -64,6 +65,7 @@ bool uplink_init(dnbd3_image_t *image, int sock, dnbd3_host_t *host, int version
spin_init( &link->rttLock, PTHREAD_PROCESS_PRIVATE );
link->image = image;
link->bytesReceived = 0;
+ link->lastBytesReceived = 0;
link->queueLen = 0;
link->fd = -1;
link->signal = NULL;
@@ -378,6 +380,7 @@ static void* uplink_mainloop(void *data)
link->fd = -1;
close( fd );
}
+ uplink_updateGlobalReceivedCounter( link );
}
// See if we should trigger an RTT measurement
spin_lock( &link->rttLock );
@@ -457,9 +460,7 @@ static void* uplink_mainloop(void *data)
spin_destroy( &link->rttLock );
free( link->recvBuffer );
link->recvBuffer = NULL;
- spin_lock( &statisticsReceivedLock );
- totalBytesReceived += link->bytesReceived;
- spin_unlock( &statisticsReceivedLock );
+ uplink_updateGlobalReceivedCounter( link );
free( link );
return NULL ;
}
@@ -648,7 +649,6 @@ static void uplink_handleReceive(dnbd3_connection_t *link)
pthread_mutex_unlock( &client->sendMutex );
if ( bytesSent != 0 ) {
client->bytesSent += bytesSent;
- client->tmpBytesSent += bytesSent;
}
spin_unlock( &client->statsLock );
spin_lock( &link->queueLock );
@@ -722,3 +722,12 @@ static void uplink_addCrc32(dnbd3_connection_t *uplink)
close( fd );
}
}
+
+static void uplink_updateGlobalReceivedCounter(dnbd3_connection_t *link)
+{
+ spin_lock( &statisticsReceivedLock );
+ totalBytesReceived += ( link->bytesReceived - link->lastBytesReceived );
+ link->lastBytesReceived = 0;
+ spin_unlock( &statisticsReceivedLock );
+}
+