summaryrefslogtreecommitdiffstats
path: root/src/server/net.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/net.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/net.c')
-rw-r--r--src/server/net.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/server/net.c b/src/server/net.c
index 09121c3..79d6cfa 100644
--- a/src/server/net.c
+++ b/src/server/net.c
@@ -61,9 +61,9 @@ static bool dnbd3_addClient(dnbd3_client_t *client);
void net_updateGlobalSentStatsFromClient(dnbd3_client_t * const client)
{
spin_lock( &statisticsSentLock );
- totalBytesSent += client->tmpBytesSent;
+ totalBytesSent += ( client->bytesSent - client->lastBytesSent );
spin_unlock( &statisticsSentLock );
- client->tmpBytesSent = 0;
+ client->lastBytesSent = client->bytesSent;
}
static inline bool recv_request_header(int sock, dnbd3_request_t *request)
@@ -197,6 +197,16 @@ void* net_handleNewConnection(void *clientPtr)
spin_init( &client->lock, PTHREAD_PROCESS_PRIVATE );
spin_init( &client->statsLock, PTHREAD_PROCESS_PRIVATE );
pthread_mutex_init( &client->sendMutex, NULL );
+
+ spin_lock( &client->lock );
+ host_to_string( &client->host, client->hostName, HOSTNAMELEN );
+ client->hostName[HOSTNAMELEN-1] = '\0';
+ spin_unlock( &client->lock );
+ spin_lock( &client->statsLock );
+ client->bytesSent = 0;
+ client->lastBytesSent = 0;
+ spin_unlock( &client->statsLock );
+
if ( !dnbd3_addClient( client ) ) {
dnbd3_freeClient( client );
logadd( LOG_WARNING, "Could not add new client to list when connecting" );
@@ -223,11 +233,6 @@ void* net_handleNewConnection(void *clientPtr)
memset( &payload, 0, sizeof(payload) );
reply.magic = dnbd3_packet_magic;
- spin_lock( &client->lock );
- host_to_string( &client->host, client->hostName, HOSTNAMELEN );
- client->hostName[HOSTNAMELEN-1] = '\0';
- spin_unlock( &client->lock );
-
// Receive first packet's payload
if ( recv_request_payload( client->sock, request.size, &payload ) ) {
char *image_name;
@@ -461,11 +466,6 @@ void* net_handleNewConnection(void *clientPtr)
spin_lock( &client->statsLock );
// Global per-client counter
client->bytesSent += request.size; // Increase counter for statistics.
- // Local counter that gets added to the global total bytes sent counter periodically
- client->tmpBytesSent += request.size;
- if ( client->tmpBytesSent > 100000000 ) {
- net_updateGlobalSentStatsFromClient( client );
- }
spin_unlock( &client->statsLock );
break;