From 897615c6e926eefe2ef78dc7cc00fe633d2ab332 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Sat, 26 Aug 2017 16:24:07 +0200 Subject: [SERVER] Split server-only defs from config.h to serverconfig.h --- src/config.h | 25 ------------------------- src/server/altservers.c | 1 + src/server/globals.c | 6 ++++-- src/server/globals.h | 7 +++++++ src/server/image.h | 3 +-- src/server/net.c | 2 +- src/server/server.h | 3 +-- src/server/serverconfig.h | 39 +++++++++++++++++++++++++++++++++++++++ 8 files changed, 54 insertions(+), 32 deletions(-) create mode 100644 src/server/serverconfig.h (limited to 'src') diff --git a/src/config.h b/src/config.h index 6699bb1..6a03069 100644 --- a/src/config.h +++ b/src/config.h @@ -21,28 +21,6 @@ #ifndef CONFIG_H_ #define CONFIG_H_ -// ############################## -// ########### SERVER ########### - -// +++++ Performance related -#define SERVER_MAX_CLIENTS 4000 -#define SERVER_MAX_IMAGES 5000 -#define SERVER_MAX_ALTS 250 -#define SERVER_MAX_UPLINK_FAILS 8 // How many times may a server fail until it is considered bad -#define SERVER_BAD_UPLINK_IGNORE 120 // How many seconds is a server considered bad? -#define SERVER_MAX_UPLINK_QUEUE 1500 // Maximum number of queued requests per uplink -#define SERVER_UPLINK_QUEUELEN_THRES 900 // Threshold where we start dropping incoming clients -#define SERVER_MAX_PENDING_ALT_CHECKS 50 -#define SERVER_CACHE_MAP_SAVE_INTERVAL 90 - -// +++++ Other magic constants -#define SERVER_RTT_PROBES 5 -#define SERVER_RTT_DELAY_INIT 5 -#define SERVER_RTT_DELAY_MAX 45 -#define SERVER_RTT_DELAY_FAILED 180 - -#define SERVER_REMOTE_IMAGE_CHECK_CACHETIME 120 // 2 minutes -#define SERVER_MAX_PROXY_IMAGE_SIZE 100000000000LL // 100GB // +++++ Network +++++ // Default port #define PORT 5003 @@ -55,15 +33,12 @@ // so either the client or server can run in compatibility mode, or they can // cancel the connection right away if the protocol has changed too much #define PROTOCOL_VERSION 2 -// Which is the minimum protocol version the server expects from the client -#define MIN_SUPPORTED_CLIENT 2 // Which is the minimum protocol version the client expects from the server #define MIN_SUPPORTED_SERVER 2 // Length of comment fields (for alt server etc.) #define COMMENT_LENGTH 120 // in seconds if not stated otherwise (MS = milliseconds) -#define SOCKET_TIMEOUT_SERVER_RETRIES 3 // When waiting for next header, max reties * above timeout is the actual total timeout (ping timeout) #define SOCKET_TIMEOUT_CLIENT_DATA 2 #define SOCKET_TIMEOUT_CLIENT_DISCOVERY 1 diff --git a/src/server/altservers.c b/src/server/altservers.c index 984271a..12450aa 100644 --- a/src/server/altservers.c +++ b/src/server/altservers.c @@ -3,6 +3,7 @@ #include "helper.h" #include "image.h" #include "../shared/protocol.h" +#include "serverconfig.h" #include #include diff --git a/src/server/globals.c b/src/server/globals.c index af4cfea..4939101 100644 --- a/src/server/globals.c +++ b/src/server/globals.c @@ -15,8 +15,9 @@ bool _isProxy = false; bool _proxyPrivateOnly = false; bool _backgroundReplication = true; int _listenPort = PORT; -int _uplinkTimeout = 1250; -int _clientTimeout = 15000; +int _uplinkTimeout = SOCKET_TIMEOUT_UPLINK; +int _clientTimeout = SOCKET_TIMEOUT_CLIENT; +bool _closeUnusedFd = false; #define SAVE_TO_VAR_STR(ss, kk) do { if (strcmp(section, #ss) == 0 && strcmp(key, #kk) == 0) { if (_ ## kk != NULL) free(_ ## kk); _ ## kk = strdup(value); } } while (0) #define SAVE_TO_VAR_BOOL(ss, kk) do { if (strcmp(section, #ss) == 0 && strcmp(key, #kk) == 0) _ ## kk = atoi(value) != 0 || strcmp(value, "true") == 0 || strcmp(value, "True") == 0 || strcmp(value, "TRUE") == 0; } while (0) @@ -32,6 +33,7 @@ static int ini_handler(void *custom UNUSED, const char* section, const char* key SAVE_TO_VAR_BOOL( dnbd3, proxyPrivateOnly ); SAVE_TO_VAR_BOOL( dnbd3, backgroundReplication ); SAVE_TO_VAR_BOOL( dnbd3, removeMissingImages ); + SAVE_TO_VAR_BOOL( dnbd3, closeUnusedFd ); SAVE_TO_VAR_INT( dnbd3, serverPenalty ); SAVE_TO_VAR_INT( dnbd3, clientPenalty ); SAVE_TO_VAR_INT( dnbd3, uplinkTimeout ); diff --git a/src/server/globals.h b/src/server/globals.h index b0dc66a..cc3b6be 100644 --- a/src/server/globals.h +++ b/src/server/globals.h @@ -3,6 +3,7 @@ #include "../types.h" #include "../shared/fdsignal.h" +#include "serverconfig.h" #include #include #include @@ -194,6 +195,12 @@ extern int _uplinkTimeout; */ extern int _clientTimeout; +/** + * If true, images with no active client will have their fd closed after some + * idle time. + */ +extern bool _closeUnusedFd; + /** * Should we replicate incomplete images in the background? * Otherwise, only blocks that were explicitly requested will be cached. diff --git a/src/server/image.h b/src/server/image.h index 718e741..d129984 100644 --- a/src/server/image.h +++ b/src/server/image.h @@ -2,10 +2,9 @@ #define _IMAGE_H_ #include "globals.h" -#include "../config.h" #include -extern dnbd3_image_t *_images[SERVER_MAX_IMAGES]; +extern dnbd3_image_t *_images[]; extern int _num_images; void image_serverStartup(); diff --git a/src/server/net.c b/src/server/net.c index 905be88..3092c7e 100644 --- a/src/server/net.c +++ b/src/server/net.c @@ -61,7 +61,7 @@ static inline bool recv_request_header(int sock, dnbd3_request_t *request) // Read request header from socket while ( ( ret = recv( sock, request, sizeof(*request), MSG_WAITALL ) ) != sizeof(*request) ) { if ( errno == EINTR && ++fails < 10 ) continue; - if ( ret >= 0 || ++fails > SOCKET_TIMEOUT_SERVER_RETRIES ) return false; + if ( ret >= 0 || ++fails > SOCKET_TIMEOUT_CLIENT_RETRIES ) return false; if ( errno == EAGAIN ) continue; logadd( LOG_DEBUG1, "Error receiving request: Could not read message header (%d/%d, e=%d)\n", ret, (int)sizeof(*request), errno ); return false; diff --git a/src/server/server.h b/src/server/server.h index 8e88fe8..00aa43c 100644 --- a/src/server/server.h +++ b/src/server/server.h @@ -22,7 +22,6 @@ #define SERVER_H_ #include "globals.h" -#include "../config.h" #include "../types.h" #include @@ -30,7 +29,7 @@ struct sockaddr_storage; -extern dnbd3_client_t *_clients[SERVER_MAX_CLIENTS]; +extern dnbd3_client_t *_clients[]; extern int _num_clients; extern pthread_spinlock_t _clients_lock; diff --git a/src/server/serverconfig.h b/src/server/serverconfig.h new file mode 100644 index 0000000..efb8476 --- /dev/null +++ b/src/server/serverconfig.h @@ -0,0 +1,39 @@ +#ifndef _SERVERCONFIG_H_ +#define _SERVERCONFIG_H_ + +#include "../config.h" + +// +++++ Performance related +#define SERVER_MAX_CLIENTS 4000 +#define SERVER_MAX_IMAGES 5000 +#define SERVER_MAX_ALTS 250 +#define SERVER_MAX_UPLINK_FAILS 8 // How many times may a server fail until it is considered bad +#define SERVER_BAD_UPLINK_IGNORE 120 // How many seconds is a server considered bad? +#define SERVER_MAX_UPLINK_QUEUE 1500 // Maximum number of queued requests per uplink +#define SERVER_UPLINK_QUEUELEN_THRES 900 // Threshold where we start dropping incoming clients +#define SERVER_MAX_PENDING_ALT_CHECKS 50 +#define SERVER_CACHE_MAP_SAVE_INTERVAL 90 + +// Time in ms to wait for a read/write call to complete on an uplink connection +#define SOCKET_TIMEOUT_UPLINK 5000 +// Same for client connections. Be a bit more liberal here +#define SOCKET_TIMEOUT_CLIENT 15000 +// When waiting for the next request header from client, allow the timeout from above +// to expire this many times. This allows for greater idle times without also increasing +// the timeout for cases where we wait for additional data or are actively sending a reply +#define SOCKET_TIMEOUT_CLIENT_RETRIES 3 + +// +++++ Other magic constants +#define SERVER_RTT_PROBES 5 +#define SERVER_RTT_DELAY_INIT 5 +#define SERVER_RTT_DELAY_MAX 45 +#define SERVER_RTT_DELAY_FAILED 180 + +#define SERVER_REMOTE_IMAGE_CHECK_CACHETIME 120 // 2 minutes +#define SERVER_MAX_PROXY_IMAGE_SIZE 100000000000LL // 100GB + +// Which is the minimum protocol version the server expects from the client +#define MIN_SUPPORTED_CLIENT 2 + +#endif + -- cgit v1.2.3-55-g7522