Commit 2f1a8340 authored by Mike Hibler's avatar Mike Hibler

Make socket buffer size more configurable.

It appeared to be before, but wasn't really. The -k option for both client
and server will set the max socketbuf size in KB (NOTE: THIS USED TO BE MB!)
The actual socketbuf size will then be the min of that and what the system
supports.

The client stats now include the sockbuf size of the run.
parent 57f3d51f
/*
* Copyright (c) 2000-2013 University of Utah and the Flux Group.
* Copyright (c) 2000-2014 University of Utah and the Flux Group.
*
* {{{EMULAB-LICENSE
*
......@@ -200,7 +200,7 @@ char *usagestr =
" -e enckeyfile File containing secret used for encrypting image\n"
"\n"
"tuning options (if you don't know what they are, don't use em!):\n"
" -k MB Max MB of memory for a socket buffer.\n"
" -k KB Max KB of memory for a socket buffer (default is 1024).\n"
" -C MB Max MB of memory to use for network chunk buffering.\n"
" -W MB Max MB of memory to use for disk write buffering.\n"
" -M MB Max MB of memory to use for buffering\n"
......@@ -358,11 +358,10 @@ main(int argc, char **argv)
case 'k':
mem = atoi(optarg);
if (mem < 1)
mem = 1;
else if (mem > 1024)
mem = 1024;
sockbufsize = mem * 1024 * 1024;
if (mem <= 0 || (mem * 1024) > MAXSOCKBUFSIZE)
sockbufsize = MAXSOCKBUFSIZE;
else
sockbufsize = mem * 1024;
break;
case 'C':
......
/*
* Copyright (c) 2000-2013 University of Utah and the Flux Group.
* Copyright (c) 2000-2014 University of Utah and the Flux Group.
*
* {{{EMULAB-LICENSE
*
......@@ -93,11 +93,14 @@
/*
* Socket buffer size, used for both send and receive in client and
* server right now. If DYN_SOCKBUFSIZE is set, we find the larger
* socketbuffer size possible that is less than or equal to SOCKBUFSIZE.
* server right now. Set to:
* min(sockbufsize, maximum-value-the-system-supports)
* where "sockbufsize" defaults to SOCKBUFSIZE but can be changed via
* the -k option to any value up to MAXSOCKBUFSIZE (a value of 0 implies
* MAXSOCKBUFSIZE).
*/
#define SOCKBUFSIZE (512 * 1024)
#define DYN_SOCKBUFSIZE 1
#define SOCKBUFSIZE (1 * 1024 * 1024)
#define MAXSOCKBUFSIZE (4 * 1024 * 1024)
/*
* The number of read-ahead chunks that the client will request
......
/*
* Copyright (c) 2000-2013 University of Utah and the Flux Group.
* Copyright (c) 2000-2014 University of Utah and the Flux Group.
*
* {{{EMULAB-LICENSE
*
......@@ -96,7 +96,6 @@ GetSockbufSize(void)
static int sbsize = 0;
if (sbsize == 0) {
#if DYN_SOCKBUFSIZE > 0
int sock;
if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
......@@ -134,9 +133,6 @@ GetSockbufSize(void)
}
}
close(sock);
#else
sbsize = sockbufsize;
#endif
FrisLog("Maximum socket buffer size of %d bytes", sbsize);
}
return sbsize;
......@@ -186,14 +182,15 @@ CommonInit(int dobind)
char buf[BUFSIZ];
struct hostent *he;
sockbufsize = GetSockbufSize();
if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
FrisPfatal("Could not allocate a socket");
i = GetSockbufSize();
i = sockbufsize;
if (setsockopt(sock, SOL_SOCKET, SO_SNDBUF, &i, sizeof(i)) < 0)
FrisPwarning("Could not set send socket buffer size to %d", i);
i = GetSockbufSize();
i = sockbufsize;
if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF, &i, sizeof(i)) < 0)
FrisPwarning("Could not set receive socket buffer size to %d",
i);
......
/*
* Copyright (c) 2000-2013 University of Utah and the Flux Group.
* Copyright (c) 2000-2014 University of Utah and the Flux Group.
*
* {{{EMULAB-LICENSE
*
......@@ -978,11 +978,11 @@ main(int argc, char **argv)
case 'k':
sockbufsize = atoi(optarg);
if (sockbufsize < 1)
sockbufsize = 1;
else if (sockbufsize > 1024)
sockbufsize = 1024;
sockbufsize *= 1024 * 1024;
if (sockbufsize <= 0 ||
(sockbufsize * 1024) > MAXSOCKBUFSIZE)
sockbufsize = MAXSOCKBUFSIZE;
else
sockbufsize *= 1024;
break;
case 'm':
......
......@@ -591,8 +591,10 @@ ClientStatsDump(unsigned int id, ClientStats_t *stats)
FrisLog(" chunk buffers: %d",
stats->u.v1.chunkbufs);
if (stats->u.v1.writebufmem)
FrisLog(" disk buffering: %dMB",
FrisLog(" disk buffering (MB): %d",
stats->u.v1.writebufmem);
FrisLog(" sockbuf size (KB): %d",
sockbufsize/1024);
FrisLog(" readahead/inprogress: %d/%d",
stats->u.v1.maxreadahead, stats->u.v1.maxinprogress);
FrisLog(" recv timo/count: %d/%d",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment