Skip to content

Commit a7db490

Browse files
committed
See changes in changelog, but...
1) memslap --flush option 2) support for no_tcpdelay (though I don't find this to be faster) 3) More tests
1 parent a488478 commit a7db490

12 files changed

+173
-11
lines changed

ChangeLog

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
0.5
2+
* Ruby maintainer mentioned TCP_NODELAY patch he had added. Added this to C
3+
library as well. (Eric Hodel [email protected])
4+
* Added support script for set_benchmark
5+
* Updated memslap to allow testing of TCP_NODELAY
6+
* Updated memslap to support --flush (aka dump memcache servers before
7+
testing)
8+
* Fixed bug in multiple hosts not being activated
9+
110
0.4 Wed Oct 3 10:28:50 PDT 2007
211
* Added buffered IO to write calls for keys
312
* Added buffered IO for reads

README

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ memcat - Copy the value of a key to standard output
88
memflush - Flush the contents of your servers.
99
memrm - Remove a key(s) from the serrver.
1010
memstat - Dump the stats of your servers to standard output
11+
memslap - Load generation utility (benchmark!)
1112

1213
This code is still in Alpha. More tests have currently been done on the
1314
library code then on the utilities.

configure.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
AC_INIT(src/memcat.c)
22
AC_CONFIG_AUX_DIR(config)
33
AM_CONFIG_HEADER(include/libmemcached_config.h)
4-
AM_INIT_AUTOMAKE("libmemcached", 0.4)
4+
AM_INIT_AUTOMAKE("libmemcached", 0.5)
55

66
AC_PROG_CC
77
AC_PROG_LIBTOOL

include/memcached.h

+4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ typedef enum {
7272
typedef enum {
7373
MEMCACHED_BEHAVIOR_NO_BLOCK,
7474
MEMCACHED_BEHAVIOR_BLOCK,
75+
MEMCACHED_BEHAVIOR_TCP_NODELAY,
76+
MEMCACHED_BEHAVIOR_TCP_DELAY,
7577
} memcached_behavior;
7678

7779
typedef enum {
@@ -115,6 +117,8 @@ struct memcached_stat_st {
115117
};
116118

117119
#define MEM_NO_BLOCK (1 << 0)
120+
#define MEM_TCP_NODELAY (1 << 1)
121+
#define MEM_REUSE_MEMORY (1 << 2)
118122

119123
struct memcached_string_st {
120124
char *string;

lib/memcached_behavior.c

+13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#include <memcached.h>
2+
#include <sys/types.h>
3+
#include <sys/socket.h>
4+
#include <netinet/tcp.h>
25

36
memcached_return memcached_behavior_set(memcached_st *ptr,
47
memcached_behavior flag,
@@ -16,6 +19,16 @@ memcached_return memcached_behavior_set(memcached_st *ptr,
1619
memcached_quit(ptr);
1720
ptr->flags+= MEM_NO_BLOCK;
1821
break;
22+
case MEMCACHED_BEHAVIOR_TCP_NODELAY:
23+
/* We quit all connections so we can reset the sockets */
24+
memcached_quit(ptr);
25+
ptr->flags|= MEM_TCP_NODELAY;
26+
break;
27+
case MEMCACHED_BEHAVIOR_TCP_DELAY:
28+
/* We quit all connections so we can reset the sockets */
29+
memcached_quit(ptr);
30+
ptr->flags+= MEM_TCP_NODELAY;
31+
break;
1932
}
2033

2134
return MEMCACHED_SUCCESS;

lib/memcached_connect.c

+17-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#include "common.h"
22

33
#include <fcntl.h>
4+
#include <sys/types.h>
5+
#include <sys/socket.h>
6+
#include <netinet/tcp.h>
47

58
memcached_return memcached_connect(memcached_st *ptr)
69
{
@@ -20,8 +23,6 @@ memcached_return memcached_connect(memcached_st *ptr)
2023
{
2124
if (ptr->hosts[x].fd == -1)
2225
{
23-
int flags;
24-
2526
if ((h= gethostbyname(ptr->hosts[x].hostname)) == NULL)
2627
return MEMCACHED_HOST_LOCKUP_FAILURE;
2728

@@ -30,7 +31,7 @@ memcached_return memcached_connect(memcached_st *ptr)
3031
servAddr.sin_port = htons(ptr->hosts[x].port);
3132

3233
/* Create the socket */
33-
if ((ptr->hosts[0].fd= socket(AF_INET, SOCK_STREAM, 0)) < 0)
34+
if ((ptr->hosts[x].fd= socket(AF_INET, SOCK_STREAM, 0)) < 0)
3435
{
3536
ptr->my_errno= errno;
3637
return MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE;
@@ -45,14 +46,24 @@ memcached_return memcached_connect(memcached_st *ptr)
4546
/* For the moment, not getting a nonblocking mode will note be fatal */
4647
if (ptr->flags & MEM_NO_BLOCK)
4748
{
48-
flags= fcntl(ptr->hosts[0].fd, F_GETFL, 0);
49+
int flags;
50+
51+
flags= fcntl(ptr->hosts[x].fd, F_GETFL, 0);
4952
if (flags != -1)
50-
(void)fcntl(ptr->hosts[0].fd, F_SETFL, flags | O_NONBLOCK);
53+
(void)fcntl(ptr->hosts[x].fd, F_SETFL, flags | O_NONBLOCK);
54+
}
55+
56+
if (ptr->flags & MEM_TCP_NODELAY)
57+
{
58+
int flag= 1;
59+
60+
setsockopt(ptr->hosts[x].fd, IPPROTO_TCP, TCP_NODELAY,
61+
&flag, (socklen_t)sizeof(int));
5162
}
5263

5364
/* connect to server */
5465
test_connect:
55-
if (connect(ptr->hosts[0].fd, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0)
66+
if (connect(ptr->hosts[x].fd, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0)
5667
{
5768
switch (errno) {
5869
/* We are spinning waiting on connect */

src/client_options.h

+2
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ typedef enum {
1414
OPT_SLAP_TEST,
1515
OPT_SLAP_CONCURRENCY,
1616
OPT_SLAP_NON_BLOCK,
17+
OPT_SLAP_TCP_NODELAY,
18+
OPT_FLUSH,
1719
} memcached_options;

src/memslap.c

+25-3
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,14 @@ struct conclusions_st {
6262
void options_parse(int argc, char *argv[]);
6363
void conclusions_print(conclusions_st *conclusion);
6464
void scheduler(memcached_server_st *servers, conclusions_st *conclusion);
65-
pairs_st *load_createial_data(memcached_server_st *servers, unsigned int number_of,
65+
pairs_st *load_create_data(memcached_server_st *servers, unsigned int number_of,
6666
unsigned int *actual_loaded);
67+
void flush_all(memcached_server_st *servers);
6768

6869
static int opt_verbose= 0;
70+
static int opt_flush= 0;
6971
static int opt_non_blocking_io= 0;
72+
static int opt_tcp_nodelay= 0;
7073
static unsigned int opt_execute_number= 0;
7174
static unsigned int opt_createial_load= 0;
7275
static unsigned int opt_concurrency= 0;
@@ -122,8 +125,10 @@ void scheduler(memcached_server_st *servers, conclusions_st *conclusion)
122125
pthread_attr_setdetachstate(&attr,
123126
PTHREAD_CREATE_DETACHED);
124127

128+
if (opt_flush)
129+
flush_all(servers);
125130
if (opt_createial_load)
126-
pairs= load_createial_data(servers, opt_createial_load, &actual_loaded);
131+
pairs= load_create_data(servers, opt_createial_load, &actual_loaded);
127132

128133
pthread_mutex_lock(&counter_mutex);
129134
thread_counter= 0;
@@ -203,10 +208,12 @@ void options_parse(int argc, char *argv[])
203208
{"debug", no_argument, &opt_verbose, OPT_DEBUG},
204209
{"execute-number", required_argument, NULL, OPT_SLAP_EXECUTE_NUMBER},
205210
{"flag", no_argument, &opt_displayflag, OPT_FLAG},
211+
{"flush", no_argument, &opt_flush, OPT_FLUSH},
206212
{"help", no_argument, NULL, OPT_HELP},
207213
{"initial-load", required_argument, NULL, OPT_SLAP_INITIAL_LOAD}, /* Number to load initially */
208214
{"non-blocking", no_argument, &opt_non_blocking_io, OPT_SLAP_NON_BLOCK},
209215
{"servers", required_argument, NULL, OPT_SERVERS},
216+
{"tcp-nodelay", no_argument, &opt_tcp_nodelay, OPT_SLAP_TCP_NODELAY},
210217
{"test", required_argument, NULL, OPT_SLAP_TEST},
211218
{"verbose", no_argument, &opt_verbose, OPT_VERBOSE},
212219
{"version", no_argument, NULL, OPT_VERSION},
@@ -299,6 +306,8 @@ void *run_task(void *p)
299306
memc= memcached_create(NULL);
300307
if (opt_non_blocking_io)
301308
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, NULL );
309+
if (opt_tcp_nodelay)
310+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, NULL );
302311

303312
memcached_server_push(memc, context->servers);
304313

@@ -333,7 +342,20 @@ void *run_task(void *p)
333342
return NULL;
334343
}
335344

336-
pairs_st *load_createial_data(memcached_server_st *servers, unsigned int number_of,
345+
void flush_all(memcached_server_st *servers)
346+
{
347+
memcached_st *memc;
348+
349+
memc= memcached_create(NULL);
350+
351+
memcached_server_push(memc, servers);
352+
353+
memcached_flush(memc, 0);
354+
355+
memcached_free(memc);
356+
}
357+
358+
pairs_st *load_create_data(memcached_server_st *servers, unsigned int number_of,
337359
unsigned int *actual_loaded)
338360
{
339361
memcached_st *memc;

support/Makefile.am

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
EXTRA_DIST = libmemcached.spec
1+
EXTRA_DIST = libmemcached.spec set_benchmark.sh

support/set_benchmark.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
src/memslap --concurrency=5 --execute-number=5000 --servers=localhost --test=set --flush
4+
src/memslap --concurrency=5 --execute-number=5000 --non-blocking --servers=localhost --test=set --flush
5+
src/memslap --concurrency=5 --execute-number=5000 --non-blocking --tcp-nodelay --servers=localhost --test=set --flush

tests/output.res

+80
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,83 @@ Found key bytes_read
154154
Found key bytes_written
155155
Found key limit_maxbytes
156156
Found key threads
157+
158+
WATCHPOINT memcached_flush.c:35 (memcached_flush)
159+
Error 0 -> SUCCESS
160+
Error 1 -> FAILURE
161+
Error 2 -> HOSTNAME LOOKUP FAILURE
162+
Error 3 -> CONNECTION FAILURE
163+
Error 4 -> CONNECTION BIND FAILURE
164+
Error 5 -> WRITE FAILURE
165+
Error 6 -> READ FAILURE
166+
Error 7 -> UNKNOWN READ FAILURE
167+
Error 8 -> PROTOCOL ERROR
168+
Error 9 -> CLIENT ERROR
169+
Error 10 -> SERVER ERROR
170+
Error 11 -> CONNECTION SOCKET CREATE FAILURE
171+
Error 12 -> CONNECTION DATA EXISTS
172+
Error 13 -> CONNECTION DATA DOES NOT EXIST
173+
Error 14 -> NOT STORED
174+
Error 15 -> STORED
175+
Error 16 -> NOT FOUND
176+
Error 17 -> MEMORY ALLOCATION FAILURE
177+
Error 18 -> PARTIAL READ
178+
Error 19 -> SOME ERRORS WERE REPORTED
179+
Error 20 -> NO SERVERS DEFINED
180+
Error 21 -> SERVER END
181+
Error 22 -> SERVER DELETE
182+
Error 23 -> SERVER VALUE
183+
184+
WATCHPOINT memcached_flush.c:35 (memcached_flush)
185+
Found key pid
186+
Found key uptime
187+
Found key time
188+
Found key version
189+
Found key pointer_size
190+
Found key rusage_user
191+
Found key rusage_system
192+
Found key rusage_user_seconds
193+
Found key rusage_user_microseconds
194+
Found key rusage_system_seconds
195+
Found key rusage_system_microseconds
196+
Found key curr_items
197+
Found key total_items
198+
Found key bytes
199+
Found key curr_connections
200+
Found key total_connections
201+
Found key connection_structures
202+
Found key cmd_get
203+
Found key cmd_set
204+
Found key get_hits
205+
Found key get_misses
206+
Found key evictions
207+
Found key bytes_read
208+
Found key bytes_written
209+
Found key limit_maxbytes
210+
Found key threads
211+
Found key pid
212+
Found key uptime
213+
Found key time
214+
Found key version
215+
Found key pointer_size
216+
Found key rusage_user
217+
Found key rusage_system
218+
Found key rusage_user_seconds
219+
Found key rusage_user_microseconds
220+
Found key rusage_system_seconds
221+
Found key rusage_system_microseconds
222+
Found key curr_items
223+
Found key total_items
224+
Found key bytes
225+
Found key curr_connections
226+
Found key total_connections
227+
Found key connection_structures
228+
Found key cmd_get
229+
Found key cmd_set
230+
Found key get_hits
231+
Found key get_misses
232+
Found key evictions
233+
Found key bytes_read
234+
Found key bytes_written
235+
Found key limit_maxbytes
236+
Found key threads

tests/test.c

+15
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,21 @@ int main(int argc, char *argv[])
626626
memcached_free(memc);
627627
}
628628

629+
fprintf(stderr, "\nTCP Nodelay tests\n\n");
630+
for (x= 0; tests[x].function_name; x++)
631+
{
632+
memcached_st *memc;
633+
memc= memcached_create(NULL);
634+
assert(memc);
635+
fprintf(stderr, "Testing %s", tests[x].function_name);
636+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, NULL);
637+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, NULL);
638+
tests[x].function(memc);
639+
fprintf(stderr, "\t\t\t\t\t[ ok ]\n");
640+
assert(memc);
641+
memcached_free(memc);
642+
}
643+
629644

630645
/* The multiple tests */
631646
if (argc == 2)

0 commit comments

Comments
 (0)