memcached 1.2.6 → 1.2.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (225) hide show
  1. data/CHANGELOG +2 -0
  2. data/Manifest +206 -12
  3. data/Rakefile +32 -1
  4. data/ext/extconf.rb +10 -35
  5. data/ext/libmemcached-0.32/AUTHORS +7 -0
  6. data/ext/libmemcached-0.32/COPYING +32 -0
  7. data/ext/libmemcached-0.32/ChangeLog +303 -0
  8. data/ext/libmemcached-0.32/INSTALL +302 -0
  9. data/ext/libmemcached-0.32/Makefile.am +36 -0
  10. data/ext/libmemcached-0.32/Makefile.in +828 -0
  11. data/ext/libmemcached-0.32/NEWS +1 -0
  12. data/ext/libmemcached-0.32/README +33 -0
  13. data/ext/libmemcached-0.32/THANKS +14 -0
  14. data/ext/libmemcached-0.32/TODO +11 -0
  15. data/ext/libmemcached-0.32/aclocal.m4 +1852 -0
  16. data/ext/libmemcached-0.32/clients/Makefile.am +73 -0
  17. data/ext/libmemcached-0.32/clients/Makefile.in +770 -0
  18. data/ext/libmemcached-0.32/clients/client_options.h +32 -0
  19. data/ext/libmemcached-0.32/clients/execute.c +64 -0
  20. data/ext/libmemcached-0.32/clients/execute.h +5 -0
  21. data/ext/libmemcached-0.32/clients/generator.c +74 -0
  22. data/ext/libmemcached-0.32/clients/generator.h +20 -0
  23. data/ext/libmemcached-0.32/clients/memcat.c +178 -0
  24. data/ext/libmemcached-0.32/clients/memcp.c +251 -0
  25. data/ext/libmemcached-0.32/clients/memdump.c +170 -0
  26. data/ext/libmemcached-0.32/clients/memerror.c +80 -0
  27. data/ext/libmemcached-0.32/clients/memflush.c +143 -0
  28. data/ext/libmemcached-0.32/clients/memrm.c +160 -0
  29. data/ext/libmemcached-0.32/clients/memslap.c +441 -0
  30. data/ext/libmemcached-0.32/clients/memstat.c +326 -0
  31. data/ext/libmemcached-0.32/clients/utilities.c +207 -0
  32. data/ext/libmemcached-0.32/clients/utilities.h +41 -0
  33. data/ext/libmemcached-0.32/config.h.in +252 -0
  34. data/ext/libmemcached-0.32/config/compile +143 -0
  35. data/ext/libmemcached-0.32/config/config.guess +1561 -0
  36. data/ext/libmemcached-0.32/config/config.rpath +666 -0
  37. data/ext/libmemcached-0.32/config/config.sub +1686 -0
  38. data/ext/libmemcached-0.32/config/depcomp +630 -0
  39. data/ext/libmemcached-0.32/config/install-sh +520 -0
  40. data/ext/libmemcached-0.32/config/ltmain.sh +8406 -0
  41. data/ext/libmemcached-0.32/config/missing +376 -0
  42. data/ext/libmemcached-0.32/configure +23048 -0
  43. data/ext/libmemcached-0.32/configure.ac +122 -0
  44. data/ext/libmemcached-0.32/docs/Makefile.am +415 -0
  45. data/ext/libmemcached-0.32/docs/Makefile.in +918 -0
  46. data/ext/libmemcached-0.32/docs/libmemcached.pod +123 -0
  47. data/ext/libmemcached-0.32/docs/libmemcached_examples.pod +115 -0
  48. data/ext/libmemcached-0.32/docs/libmemcachedutil.pod +40 -0
  49. data/ext/libmemcached-0.32/docs/memcached_analyze.pod +52 -0
  50. data/ext/libmemcached-0.32/docs/memcached_auto.pod +97 -0
  51. data/ext/libmemcached-0.32/docs/memcached_behavior.pod +224 -0
  52. data/ext/libmemcached-0.32/docs/memcached_callback.pod +123 -0
  53. data/ext/libmemcached-0.32/docs/memcached_create.pod +61 -0
  54. data/ext/libmemcached-0.32/docs/memcached_delete.pod +54 -0
  55. data/ext/libmemcached-0.32/docs/memcached_dump.pod +53 -0
  56. data/ext/libmemcached-0.32/docs/memcached_flush.pod +46 -0
  57. data/ext/libmemcached-0.32/docs/memcached_flush_buffers.pod +42 -0
  58. data/ext/libmemcached-0.32/docs/memcached_generate_hash_value.pod +57 -0
  59. data/ext/libmemcached-0.32/docs/memcached_get.pod +161 -0
  60. data/ext/libmemcached-0.32/docs/memcached_memory_allocators.pod +73 -0
  61. data/ext/libmemcached-0.32/docs/memcached_pool.pod +77 -0
  62. data/ext/libmemcached-0.32/docs/memcached_quit.pod +47 -0
  63. data/ext/libmemcached-0.32/docs/memcached_sasl.pod +63 -0
  64. data/ext/libmemcached-0.32/docs/memcached_server_st.pod +75 -0
  65. data/ext/libmemcached-0.32/docs/memcached_servers.pod +102 -0
  66. data/ext/libmemcached-0.32/docs/memcached_set.pod +187 -0
  67. data/ext/libmemcached-0.32/docs/memcached_stats.pod +82 -0
  68. data/ext/libmemcached-0.32/docs/memcached_strerror.pod +46 -0
  69. data/ext/libmemcached-0.32/docs/memcached_user_data.pod +49 -0
  70. data/ext/libmemcached-0.32/docs/memcached_verbosity.pod +41 -0
  71. data/ext/libmemcached-0.32/docs/memcached_version.pod +56 -0
  72. data/ext/libmemcached-0.32/docs/memcat.pod +37 -0
  73. data/ext/libmemcached-0.32/docs/memcp.pod +40 -0
  74. data/ext/libmemcached-0.32/docs/memdump.pod +31 -0
  75. data/ext/libmemcached-0.32/docs/memerror.pod +30 -0
  76. data/ext/libmemcached-0.32/docs/memflush.pod +35 -0
  77. data/ext/libmemcached-0.32/docs/memrm.pod +34 -0
  78. data/ext/libmemcached-0.32/docs/memslap.pod +33 -0
  79. data/ext/libmemcached-0.32/docs/memstat.pod +35 -0
  80. data/ext/libmemcached-0.32/libmemcached/Makefile.am +107 -0
  81. data/ext/libmemcached-0.32/libmemcached/Makefile.in +1050 -0
  82. data/ext/libmemcached-0.32/libmemcached/byteorder.c +31 -0
  83. data/ext/libmemcached-0.32/libmemcached/common.h +183 -0
  84. data/ext/libmemcached-0.32/libmemcached/crc.c +86 -0
  85. data/ext/libmemcached-0.32/libmemcached/hsieh_hash.c +68 -0
  86. data/ext/libmemcached-0.32/libmemcached/jenkins_hash.c +213 -0
  87. data/ext/libmemcached-0.32/libmemcached/libmemcached.ver +1 -0
  88. data/ext/libmemcached-0.32/libmemcached/libmemcached_probes.d +28 -0
  89. data/ext/libmemcached-0.32/libmemcached/libmemcached_probes.h +78 -0
  90. data/ext/libmemcached-0.32/libmemcached/md5.c +354 -0
  91. data/ext/libmemcached-0.32/libmemcached/memcached.c +152 -0
  92. data/ext/libmemcached-0.32/libmemcached/memcached.h +302 -0
  93. data/ext/libmemcached-0.32/libmemcached/memcached.hpp +799 -0
  94. data/ext/libmemcached-0.32/libmemcached/memcached/README.txt +7 -0
  95. data/ext/libmemcached-0.32/libmemcached/memcached/protocol_binary.h +366 -0
  96. data/ext/libmemcached-0.32/libmemcached/memcached_allocators.c +72 -0
  97. data/ext/libmemcached-0.32/libmemcached/memcached_analyze.c +100 -0
  98. data/ext/libmemcached-0.32/libmemcached/memcached_auto.c +207 -0
  99. data/ext/libmemcached-0.32/libmemcached/memcached_behavior.c +285 -0
  100. data/ext/libmemcached-0.32/libmemcached/memcached_callback.c +175 -0
  101. data/ext/libmemcached-0.32/libmemcached/memcached_configure.h.in +23 -0
  102. data/ext/libmemcached-0.32/libmemcached/memcached_connect.c +361 -0
  103. data/ext/libmemcached-0.32/libmemcached/memcached_constants.h +145 -0
  104. data/ext/libmemcached-0.32/libmemcached/memcached_delete.c +0 -0
  105. data/ext/libmemcached-0.32/libmemcached/memcached_do.c +34 -0
  106. data/ext/libmemcached-0.32/libmemcached/memcached_dump.c +79 -0
  107. data/ext/libmemcached-0.32/libmemcached/memcached_fetch.c +102 -0
  108. data/ext/libmemcached-0.32/libmemcached/memcached_flush.c +89 -0
  109. data/ext/libmemcached-0.32/libmemcached/memcached_flush_buffers.c +22 -0
  110. data/ext/libmemcached-0.32/libmemcached/memcached_get.c +495 -0
  111. data/ext/libmemcached-0.32/libmemcached/memcached_get.h +87 -0
  112. data/ext/libmemcached-0.32/libmemcached/memcached_hash.c +252 -0
  113. data/ext/libmemcached-0.32/libmemcached/memcached_hosts.c +510 -0
  114. data/ext/libmemcached-0.32/libmemcached/memcached_internal.h +31 -0
  115. data/ext/libmemcached-0.32/libmemcached/memcached_io.c +547 -0
  116. data/ext/libmemcached-0.32/libmemcached/memcached_io.h +59 -0
  117. data/ext/libmemcached-0.32/libmemcached/memcached_key.c +28 -0
  118. data/ext/libmemcached-0.32/libmemcached/memcached_parse.c +74 -0
  119. data/ext/libmemcached-0.32/libmemcached/memcached_pool.h +38 -0
  120. data/ext/libmemcached-0.32/libmemcached/memcached_purge.c +76 -0
  121. data/ext/libmemcached-0.32/libmemcached/memcached_quit.c +75 -0
  122. data/ext/libmemcached-0.32/libmemcached/memcached_response.c +528 -0
  123. data/ext/libmemcached-0.32/libmemcached/memcached_result.c +57 -0
  124. data/ext/libmemcached-0.32/libmemcached/memcached_result.h +59 -0
  125. data/ext/libmemcached-0.32/libmemcached/memcached_sasl.c +225 -0
  126. data/ext/libmemcached-0.32/libmemcached/memcached_sasl.h +44 -0
  127. data/ext/libmemcached-0.32/libmemcached/memcached_server.c +159 -0
  128. data/ext/libmemcached-0.32/libmemcached/memcached_server.h +93 -0
  129. data/ext/libmemcached-0.32/libmemcached/memcached_stats.c +454 -0
  130. data/ext/libmemcached-0.32/libmemcached/memcached_storage.c +514 -0
  131. data/ext/libmemcached-0.32/libmemcached/memcached_storage.h +107 -0
  132. data/ext/libmemcached-0.32/libmemcached/memcached_strerror.c +92 -0
  133. data/ext/libmemcached-0.32/libmemcached/memcached_string.c +138 -0
  134. data/ext/libmemcached-0.32/libmemcached/memcached_string.h +53 -0
  135. data/ext/libmemcached-0.32/libmemcached/memcached_types.h +44 -0
  136. data/ext/libmemcached-0.32/libmemcached/memcached_util.h +15 -0
  137. data/ext/libmemcached-0.32/libmemcached/memcached_verbosity.c +36 -0
  138. data/ext/libmemcached-0.32/libmemcached/memcached_version.c +112 -0
  139. data/ext/libmemcached-0.32/libmemcached/memcached_watchpoint.h +38 -0
  140. data/ext/libmemcached-0.32/libmemcached/murmur_hash.c +76 -0
  141. data/ext/libmemcached-0.32/libmemcached/visibility.h +51 -0
  142. data/ext/libmemcached-0.32/libmemcachedutil/Makefile.am +11 -0
  143. data/ext/libmemcached-0.32/libmemcachedutil/Makefile.in +602 -0
  144. data/ext/libmemcached-0.32/libmemcachedutil/libmemcachedutil.ver +1 -0
  145. data/ext/libmemcached-0.32/libmemcachedutil/memcached_pool.c +170 -0
  146. data/ext/libmemcached-0.32/m4/ac_cxx_compile_stdcxx_0x.m4 +103 -0
  147. data/ext/libmemcached-0.32/m4/ac_cxx_header_stdcxx_98.m4 +67 -0
  148. data/ext/libmemcached-0.32/m4/acx_pthread.m4 +276 -0
  149. data/ext/libmemcached-0.32/m4/byteorder.m4 +40 -0
  150. data/ext/libmemcached-0.32/m4/deprecated.m4 +17 -0
  151. data/ext/libmemcached-0.32/m4/enable_utillib.m4 +16 -0
  152. data/ext/libmemcached-0.32/m4/extensions.m4 +94 -0
  153. data/ext/libmemcached-0.32/m4/hsieh.m4 +18 -0
  154. data/ext/libmemcached-0.32/m4/lib-prefix.m4 +221 -0
  155. data/ext/libmemcached-0.32/m4/libtool.m4 +7360 -0
  156. data/ext/libmemcached-0.32/m4/ltoptions.m4 +368 -0
  157. data/ext/libmemcached-0.32/m4/ltsugar.m4 +123 -0
  158. data/ext/libmemcached-0.32/m4/ltversion.m4 +23 -0
  159. data/ext/libmemcached-0.32/m4/lt~obsolete.m4 +92 -0
  160. data/ext/libmemcached-0.32/m4/memcached.m4 +30 -0
  161. data/ext/libmemcached-0.32/m4/pandora_64bit.m4 +55 -0
  162. data/ext/libmemcached-0.32/m4/pandora_canonical.m4 +151 -0
  163. data/ext/libmemcached-0.32/m4/pandora_check_compiler_version.m4 +37 -0
  164. data/ext/libmemcached-0.32/m4/pandora_check_cxx_standard.m4 +16 -0
  165. data/ext/libmemcached-0.32/m4/pandora_enable_dtrace.m4 +41 -0
  166. data/ext/libmemcached-0.32/m4/pandora_ensure_gcc_version.m4 +36 -0
  167. data/ext/libmemcached-0.32/m4/pandora_have_better_malloc.m4 +54 -0
  168. data/ext/libmemcached-0.32/m4/pandora_have_sasl.m4 +133 -0
  169. data/ext/libmemcached-0.32/m4/pandora_header_assert.m4 +23 -0
  170. data/ext/libmemcached-0.32/m4/pandora_libtool.m4 +15 -0
  171. data/ext/libmemcached-0.32/m4/pandora_optimize.m4 +79 -0
  172. data/ext/libmemcached-0.32/m4/pandora_shared_ptr.m4 +56 -0
  173. data/ext/libmemcached-0.32/m4/pandora_vc_build.m4 +32 -0
  174. data/ext/libmemcached-0.32/m4/pandora_warnings.m4 +262 -0
  175. data/ext/libmemcached-0.32/m4/pod2man.m4 +7 -0
  176. data/ext/libmemcached-0.32/m4/protocol_binary.m4 +23 -0
  177. data/ext/libmemcached-0.32/m4/setsockopt.m4 +57 -0
  178. data/ext/libmemcached-0.32/m4/visibility.m4 +52 -0
  179. data/ext/libmemcached-0.32/support/Makefile.am +4 -0
  180. data/ext/libmemcached-0.32/support/Makefile.in +485 -0
  181. data/ext/libmemcached-0.32/support/libmemcached-fc.spec.in +105 -0
  182. data/ext/libmemcached-0.32/support/libmemcached.pc.in +10 -0
  183. data/ext/libmemcached-0.32/support/libmemcached.spec +105 -0
  184. data/ext/libmemcached-0.32/support/libmemcached.spec.in +105 -0
  185. data/ext/libmemcached-0.32/support/set_benchmark.sh +5 -0
  186. data/ext/libmemcached-0.32/tests/Makefile.am +105 -0
  187. data/ext/libmemcached-0.32/tests/Makefile.in +748 -0
  188. data/ext/libmemcached-0.32/tests/atomsmasher.c +245 -0
  189. data/ext/libmemcached-0.32/tests/function.c +4781 -0
  190. data/ext/libmemcached-0.32/tests/ketama_test_cases.h +108 -0
  191. data/ext/libmemcached-0.32/tests/output.cmp +7 -0
  192. data/ext/libmemcached-0.32/tests/output.res +7 -0
  193. data/ext/libmemcached-0.32/tests/output2.res +46 -0
  194. data/ext/libmemcached-0.32/tests/plus.cpp +293 -0
  195. data/ext/libmemcached-0.32/tests/r/memcat.res +19 -0
  196. data/ext/libmemcached-0.32/tests/r/memcp.res +27 -0
  197. data/ext/libmemcached-0.32/tests/r/memrm.res +19 -0
  198. data/ext/libmemcached-0.32/tests/r/memslap.res +33 -0
  199. data/ext/libmemcached-0.32/tests/r/memstat.res +33 -0
  200. data/ext/libmemcached-0.32/tests/server.c +118 -0
  201. data/ext/libmemcached-0.32/tests/server.h +25 -0
  202. data/ext/libmemcached-0.32/tests/start.c +16 -0
  203. data/ext/libmemcached-0.32/tests/t/memcat.test +4 -0
  204. data/ext/libmemcached-0.32/tests/t/memcp.test +3 -0
  205. data/ext/libmemcached-0.32/tests/t/memrm.test +3 -0
  206. data/ext/libmemcached-0.32/tests/t/memslap.test +5 -0
  207. data/ext/libmemcached-0.32/tests/t/memstat.test +3 -0
  208. data/ext/libmemcached-0.32/tests/test.c +137 -0
  209. data/ext/libmemcached-0.32/tests/test.h +46 -0
  210. data/ext/libmemcached-0.32/tests/udp.c +76 -0
  211. data/memcached.gemspec +4 -4
  212. data/test/unit/memcached_test.rb +30 -0
  213. metadata +213 -16
  214. data/ext/libmemcached-0.32.tar.gz +0 -0
  215. data/ext/libmemcached-1.patch +0 -270
  216. data/ext/libmemcached-10.patch +0 -12
  217. data/ext/libmemcached-2.patch +0 -116
  218. data/ext/libmemcached-3.patch +0 -8
  219. data/ext/libmemcached-4.patch +0 -40
  220. data/ext/libmemcached-5.patch +0 -832
  221. data/ext/libmemcached-6.patch +0 -20
  222. data/ext/libmemcached-7.patch +0 -2989
  223. data/ext/libmemcached-8.patch +0 -137
  224. data/ext/libmemcached-9.patch +0 -13
  225. data/ext/sasl.patch +0 -29283
@@ -0,0 +1,441 @@
1
+ #include "libmemcached/common.h"
2
+ #include <stdio.h>
3
+ #include <stdlib.h>
4
+ #include <string.h>
5
+ #include <sys/types.h>
6
+ #include <sys/stat.h>
7
+ #include <sys/types.h>
8
+ #include <sys/mman.h>
9
+ #include <fcntl.h>
10
+ #include <sys/time.h>
11
+ #include <getopt.h>
12
+ #include <pthread.h>
13
+ #include <assert.h>
14
+
15
+ #include <libmemcached/memcached.h>
16
+
17
+ #include "client_options.h"
18
+ #include "utilities.h"
19
+ #include "generator.h"
20
+ #include "execute.h"
21
+
22
+ #define DEFAULT_INITIAL_LOAD 10000
23
+ #define DEFAULT_EXECUTE_NUMBER 10000
24
+ #define DEFAULT_CONCURRENCY 1
25
+
26
+ #define PROGRAM_NAME "memslap"
27
+ #define PROGRAM_DESCRIPTION "Generates a load against a memcached custer of servers."
28
+
29
+ /* Global Thread counter */
30
+ volatile unsigned int thread_counter;
31
+ pthread_mutex_t counter_mutex;
32
+ pthread_cond_t count_threshhold;
33
+ volatile unsigned int master_wakeup;
34
+ pthread_mutex_t sleeper_mutex;
35
+ pthread_cond_t sleep_threshhold;
36
+
37
+ void *run_task(void *p);
38
+
39
+ /* Types */
40
+ typedef struct conclusions_st conclusions_st;
41
+ typedef struct thread_context_st thread_context_st;
42
+ typedef enum {
43
+ SET_TEST,
44
+ GET_TEST,
45
+ } test_type;
46
+
47
+ struct thread_context_st {
48
+ unsigned int key_count;
49
+ pairs_st *initial_pairs;
50
+ unsigned int initial_number;
51
+ pairs_st *execute_pairs;
52
+ unsigned int execute_number;
53
+ test_type test;
54
+ memcached_st *memc;
55
+ };
56
+
57
+ struct conclusions_st {
58
+ long int load_time;
59
+ long int read_time;
60
+ unsigned int rows_loaded;
61
+ unsigned int rows_read;
62
+ };
63
+
64
+ /* Prototypes */
65
+ void options_parse(int argc, char *argv[]);
66
+ void conclusions_print(conclusions_st *conclusion);
67
+ void scheduler(memcached_server_st *servers, conclusions_st *conclusion);
68
+ pairs_st *load_create_data(memcached_st *memc, unsigned int number_of,
69
+ unsigned int *actual_loaded);
70
+ void flush_all(memcached_st *memc);
71
+
72
+ static int opt_binary= 0;
73
+ static int opt_verbose= 0;
74
+ static int opt_flush= 0;
75
+ static int opt_non_blocking_io= 0;
76
+ static int opt_tcp_nodelay= 0;
77
+ static unsigned int opt_execute_number= 0;
78
+ static unsigned int opt_createial_load= 0;
79
+ static unsigned int opt_concurrency= 0;
80
+ static int opt_displayflag= 0;
81
+ static char *opt_servers= NULL;
82
+ static int opt_udp_io= 0;
83
+ static char *opt_username;
84
+ static char *opt_passwd;
85
+
86
+ test_type opt_test= SET_TEST;
87
+
88
+ int main(int argc, char *argv[])
89
+ {
90
+ conclusions_st conclusion;
91
+ memcached_server_st *servers;
92
+
93
+ memset(&conclusion, 0, sizeof(conclusions_st));
94
+
95
+ srandom((unsigned int)time(NULL));
96
+ options_parse(argc, argv);
97
+
98
+ if (!opt_servers)
99
+ {
100
+ char *temp;
101
+
102
+ if ((temp= getenv("MEMCACHED_SERVERS")))
103
+ opt_servers= strdup(temp);
104
+ else
105
+ {
106
+ fprintf(stderr, "No Servers provided\n");
107
+ exit(1);
108
+ }
109
+ }
110
+
111
+ servers= memcached_servers_parse(opt_servers);
112
+
113
+ pthread_mutex_init(&counter_mutex, NULL);
114
+ pthread_cond_init(&count_threshhold, NULL);
115
+ pthread_mutex_init(&sleeper_mutex, NULL);
116
+ pthread_cond_init(&sleep_threshhold, NULL);
117
+
118
+ scheduler(servers, &conclusion);
119
+
120
+ free(opt_servers);
121
+
122
+ (void)pthread_mutex_destroy(&counter_mutex);
123
+ (void)pthread_cond_destroy(&count_threshhold);
124
+ (void)pthread_mutex_destroy(&sleeper_mutex);
125
+ (void)pthread_cond_destroy(&sleep_threshhold);
126
+ conclusions_print(&conclusion);
127
+ memcached_server_list_free(servers);
128
+
129
+ return 0;
130
+ }
131
+
132
+ void scheduler(memcached_server_st *servers, conclusions_st *conclusion)
133
+ {
134
+ unsigned int x;
135
+ unsigned int actual_loaded= 0; /* Fix warning */
136
+ memcached_st *memc;
137
+
138
+ struct timeval start_time, end_time;
139
+ pthread_t mainthread; /* Thread descriptor */
140
+ pthread_attr_t attr; /* Thread attributes */
141
+ pairs_st *pairs= NULL;
142
+
143
+ pthread_attr_init(&attr);
144
+ pthread_attr_setdetachstate(&attr,
145
+ PTHREAD_CREATE_DETACHED);
146
+
147
+ memc= memcached_create(NULL);
148
+
149
+ /* We need to set udp behavior before adding servers to the client */
150
+ if (opt_udp_io)
151
+ {
152
+ memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_USE_UDP,
153
+ (uint64_t)opt_udp_io);
154
+ for(x= 0; x < servers[0].count; x++ )
155
+ servers[x].type= MEMCACHED_CONNECTION_UDP;
156
+ }
157
+ memcached_server_push(memc, servers);
158
+
159
+ memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL,
160
+ (uint64_t)opt_binary);
161
+ if (!initialize_sasl(memc, opt_username, opt_passwd))
162
+ {
163
+ memcached_free(memc);
164
+ exit(1);
165
+ }
166
+
167
+ if (opt_flush)
168
+ flush_all(memc);
169
+ if (opt_createial_load)
170
+ pairs= load_create_data(memc, opt_createial_load, &actual_loaded);
171
+
172
+ /* We set this after we have loaded */
173
+ {
174
+ if (opt_non_blocking_io)
175
+ memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, 1);
176
+ if (opt_tcp_nodelay)
177
+ memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, 1);
178
+ }
179
+
180
+
181
+ pthread_mutex_lock(&counter_mutex);
182
+ thread_counter= 0;
183
+
184
+ pthread_mutex_lock(&sleeper_mutex);
185
+ master_wakeup= 1;
186
+ pthread_mutex_unlock(&sleeper_mutex);
187
+
188
+ for (x= 0; x < opt_concurrency; x++)
189
+ {
190
+ thread_context_st *context;
191
+ context= (thread_context_st *)calloc(1, sizeof(thread_context_st));
192
+
193
+ context->memc= memcached_clone(NULL, memc);
194
+ context->test= opt_test;
195
+
196
+ context->initial_pairs= pairs;
197
+ context->initial_number= actual_loaded;
198
+
199
+ if (opt_test == SET_TEST)
200
+ {
201
+ context->execute_pairs= pairs_generate(opt_execute_number, 400);
202
+ context->execute_number= opt_execute_number;
203
+ }
204
+
205
+ /* now you create the thread */
206
+ if (pthread_create(&mainthread, &attr, run_task,
207
+ (void *)context) != 0)
208
+ {
209
+ fprintf(stderr,"Could not create thread\n");
210
+ exit(1);
211
+ }
212
+ thread_counter++;
213
+ }
214
+
215
+ pthread_mutex_unlock(&counter_mutex);
216
+ pthread_attr_destroy(&attr);
217
+
218
+ pthread_mutex_lock(&sleeper_mutex);
219
+ master_wakeup= 0;
220
+ pthread_mutex_unlock(&sleeper_mutex);
221
+ pthread_cond_broadcast(&sleep_threshhold);
222
+
223
+ gettimeofday(&start_time, NULL);
224
+ /*
225
+ We loop until we know that all children have cleaned up.
226
+ */
227
+ pthread_mutex_lock(&counter_mutex);
228
+ while (thread_counter)
229
+ pthread_cond_wait(&count_threshhold, &counter_mutex);
230
+ pthread_mutex_unlock(&counter_mutex);
231
+
232
+ gettimeofday(&end_time, NULL);
233
+
234
+ conclusion->load_time= timedif(end_time, start_time);
235
+ conclusion->read_time= timedif(end_time, start_time);
236
+ pairs_free(pairs);
237
+ memcached_free(memc);
238
+ shutdown_sasl();
239
+ }
240
+
241
+
242
+ void options_parse(int argc, char *argv[])
243
+ {
244
+ memcached_programs_help_st help_options[]=
245
+ {
246
+ {0},
247
+ };
248
+
249
+ static struct option long_options[]=
250
+ {
251
+ {(OPTIONSTRING)"concurrency", required_argument, NULL, OPT_SLAP_CONCURRENCY},
252
+ {(OPTIONSTRING)"debug", no_argument, &opt_verbose, OPT_DEBUG},
253
+ {(OPTIONSTRING)"execute-number", required_argument, NULL, OPT_SLAP_EXECUTE_NUMBER},
254
+ {(OPTIONSTRING)"flag", no_argument, &opt_displayflag, OPT_FLAG},
255
+ {(OPTIONSTRING)"flush", no_argument, &opt_flush, OPT_FLUSH},
256
+ {(OPTIONSTRING)"help", no_argument, NULL, OPT_HELP},
257
+ {(OPTIONSTRING)"initial-load", required_argument, NULL, OPT_SLAP_INITIAL_LOAD}, /* Number to load initially */
258
+ {(OPTIONSTRING)"non-blocking", no_argument, &opt_non_blocking_io, OPT_SLAP_NON_BLOCK},
259
+ {(OPTIONSTRING)"servers", required_argument, NULL, OPT_SERVERS},
260
+ {(OPTIONSTRING)"tcp-nodelay", no_argument, &opt_tcp_nodelay, OPT_SLAP_TCP_NODELAY},
261
+ {(OPTIONSTRING)"test", required_argument, NULL, OPT_SLAP_TEST},
262
+ {(OPTIONSTRING)"verbose", no_argument, &opt_verbose, OPT_VERBOSE},
263
+ {(OPTIONSTRING)"version", no_argument, NULL, OPT_VERSION},
264
+ {(OPTIONSTRING)"binary", no_argument, NULL, OPT_BINARY},
265
+ {(OPTIONSTRING)"udp", no_argument, NULL, OPT_UDP},
266
+ {(OPTIONSTRING)"username", required_argument, NULL, OPT_USERNAME},
267
+ {(OPTIONSTRING)"password", required_argument, NULL, OPT_PASSWD},
268
+ {0, 0, 0, 0},
269
+ };
270
+
271
+ int option_index= 0;
272
+ int option_rv;
273
+
274
+ while (1)
275
+ {
276
+ option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index);
277
+ if (option_rv == -1) break;
278
+ switch (option_rv)
279
+ {
280
+ case 0:
281
+ break;
282
+ case OPT_UDP:
283
+ if (opt_test == GET_TEST)
284
+ {
285
+ fprintf(stderr, "You can not run a get test in UDP mode. UDP mode "
286
+ "does not currently support get ops.\n");
287
+ exit(1);
288
+ }
289
+ opt_udp_io= 1;
290
+ break;
291
+ case OPT_BINARY:
292
+ opt_binary = 1;
293
+ break;
294
+ case OPT_VERBOSE: /* --verbose or -v */
295
+ opt_verbose = OPT_VERBOSE;
296
+ break;
297
+ case OPT_DEBUG: /* --debug or -d */
298
+ opt_verbose = OPT_DEBUG;
299
+ break;
300
+ case OPT_VERSION: /* --version or -V */
301
+ version_command(PROGRAM_NAME);
302
+ break;
303
+ case OPT_HELP: /* --help or -h */
304
+ help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, help_options);
305
+ break;
306
+ case OPT_SERVERS: /* --servers or -s */
307
+ opt_servers= strdup(optarg);
308
+ break;
309
+ case OPT_SLAP_TEST:
310
+ if (!strcmp(optarg, "get"))
311
+ {
312
+ if (opt_udp_io == 1)
313
+ {
314
+ fprintf(stderr, "You can not run a get test in UDP mode. UDP mode "
315
+ "does not currently support get ops.\n");
316
+ exit(1);
317
+ }
318
+ opt_test= GET_TEST ;
319
+ }
320
+ else if (!strcmp(optarg, "set"))
321
+ opt_test= SET_TEST;
322
+ else
323
+ {
324
+ fprintf(stderr, "Your test, %s, is not a known test\n", optarg);
325
+ exit(1);
326
+ }
327
+ break;
328
+ case OPT_SLAP_CONCURRENCY:
329
+ opt_concurrency= (unsigned int)strtoul(optarg, (char **)NULL, 10);
330
+ break;
331
+ case OPT_SLAP_EXECUTE_NUMBER:
332
+ opt_execute_number= (unsigned int)strtoul(optarg, (char **)NULL, 10);
333
+ break;
334
+ case OPT_SLAP_INITIAL_LOAD:
335
+ opt_createial_load= (unsigned int)strtoul(optarg, (char **)NULL, 10);
336
+ break;
337
+ case OPT_USERNAME:
338
+ opt_username= optarg;
339
+ break;
340
+ case OPT_PASSWD:
341
+ opt_passwd= optarg;
342
+ break;
343
+ case '?':
344
+ /* getopt_long already printed an error message. */
345
+ exit(1);
346
+ default:
347
+ abort();
348
+ }
349
+ }
350
+
351
+ if (opt_test == GET_TEST && opt_createial_load == 0)
352
+ opt_createial_load= DEFAULT_INITIAL_LOAD;
353
+
354
+ if (opt_execute_number == 0)
355
+ opt_execute_number= DEFAULT_EXECUTE_NUMBER;
356
+
357
+ if (opt_concurrency == 0)
358
+ opt_concurrency= DEFAULT_CONCURRENCY;
359
+ }
360
+
361
+ void conclusions_print(conclusions_st *conclusion)
362
+ {
363
+ printf("\tThreads connecting to servers %u\n", opt_concurrency);
364
+ #ifdef NOT_FINISHED
365
+ printf("\tLoaded %u rows\n", conclusion->rows_loaded);
366
+ printf("\tRead %u rows\n", conclusion->rows_read);
367
+ #endif
368
+ if (opt_test == SET_TEST)
369
+ printf("\tTook %ld.%03ld seconds to load data\n", conclusion->load_time / 1000,
370
+ conclusion->load_time % 1000);
371
+ else
372
+ printf("\tTook %ld.%03ld seconds to read data\n", conclusion->read_time / 1000,
373
+ conclusion->read_time % 1000);
374
+ }
375
+
376
+ void *run_task(void *p)
377
+ {
378
+ thread_context_st *context= (thread_context_st *)p;
379
+ memcached_st *memc;
380
+
381
+ memc= context->memc;
382
+
383
+ pthread_mutex_lock(&sleeper_mutex);
384
+ while (master_wakeup)
385
+ {
386
+ pthread_cond_wait(&sleep_threshhold, &sleeper_mutex);
387
+ }
388
+ pthread_mutex_unlock(&sleeper_mutex);
389
+
390
+ /* Do Stuff */
391
+ switch (context->test)
392
+ {
393
+ case SET_TEST:
394
+ assert(context->execute_pairs);
395
+ execute_set(memc, context->execute_pairs, context->execute_number);
396
+ break;
397
+ case GET_TEST:
398
+ execute_get(memc, context->initial_pairs, context->initial_number);
399
+ break;
400
+ default:
401
+ WATCHPOINT_ASSERT(context->test);
402
+ break;
403
+ }
404
+
405
+ memcached_free(memc);
406
+
407
+ if (context->execute_pairs)
408
+ pairs_free(context->execute_pairs);
409
+
410
+ free(context);
411
+
412
+ pthread_mutex_lock(&counter_mutex);
413
+ thread_counter--;
414
+ pthread_cond_signal(&count_threshhold);
415
+ pthread_mutex_unlock(&counter_mutex);
416
+
417
+ return NULL;
418
+ }
419
+
420
+ void flush_all(memcached_st *memc)
421
+ {
422
+ memcached_flush(memc, 0);
423
+ }
424
+
425
+ pairs_st *load_create_data(memcached_st *memc, unsigned int number_of,
426
+ unsigned int *actual_loaded)
427
+ {
428
+ memcached_st *memc_clone;
429
+ pairs_st *pairs;
430
+
431
+ memc_clone= memcached_clone(NULL, memc);
432
+ /* We always used non-blocking IO for load since it is faster */
433
+ memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_NO_BLOCK, 0);
434
+
435
+ pairs= pairs_generate(number_of, 400);
436
+ *actual_loaded= execute_set(memc_clone, pairs, number_of);
437
+
438
+ memcached_free(memc_clone);
439
+
440
+ return pairs;
441
+ }
@@ -0,0 +1,326 @@
1
+ #include "libmemcached/common.h"
2
+ #include <stdio.h>
3
+ #include <sys/types.h>
4
+ #include <sys/stat.h>
5
+ #include <sys/types.h>
6
+ #include <sys/mman.h>
7
+ #include <fcntl.h>
8
+ #include <string.h>
9
+ #include <getopt.h>
10
+ #include <sys/time.h>
11
+
12
+ #include <libmemcached/memcached.h>
13
+
14
+ #include "client_options.h"
15
+ #include "utilities.h"
16
+
17
+ #define PROGRAM_NAME "memstat"
18
+ #define PROGRAM_DESCRIPTION "Output the state of a memcached cluster."
19
+
20
+ /* Prototypes */
21
+ static void options_parse(int argc, char *argv[]);
22
+ static void run_analyzer(memcached_st *memc, memcached_stat_st *memc_stat,
23
+ memcached_server_st *server_list);
24
+ static void print_server_listing(memcached_st *memc, memcached_stat_st *memc_stat,
25
+ memcached_server_st *server_list);
26
+ static void print_analysis_report(memcached_st *memc,
27
+ memcached_analysis_st *report,
28
+ memcached_server_st *server_list);
29
+
30
+ static int opt_verbose= 0;
31
+ static int opt_displayflag= 0;
32
+ static int opt_analyze= 0;
33
+ static char *opt_servers= NULL;
34
+ static char *analyze_mode= NULL;
35
+
36
+ static struct option long_options[]=
37
+ {
38
+ {(OPTIONSTRING)"version", no_argument, NULL, OPT_VERSION},
39
+ {(OPTIONSTRING)"help", no_argument, NULL, OPT_HELP},
40
+ {(OPTIONSTRING)"verbose", no_argument, &opt_verbose, OPT_VERBOSE},
41
+ {(OPTIONSTRING)"debug", no_argument, &opt_verbose, OPT_DEBUG},
42
+ {(OPTIONSTRING)"servers", required_argument, NULL, OPT_SERVERS},
43
+ {(OPTIONSTRING)"flag", no_argument, &opt_displayflag, OPT_FLAG},
44
+ {(OPTIONSTRING)"analyze", optional_argument, NULL, OPT_ANALYZE},
45
+ {0, 0, 0, 0},
46
+ };
47
+
48
+ int main(int argc, char *argv[])
49
+ {
50
+ memcached_return rc;
51
+ memcached_st *memc;
52
+ memcached_stat_st *memc_stat;
53
+ memcached_server_st *servers;
54
+ memcached_server_st *server_list;
55
+
56
+ options_parse(argc, argv);
57
+
58
+ if (!opt_servers)
59
+ {
60
+ char *temp;
61
+
62
+ if ((temp= getenv("MEMCACHED_SERVERS")))
63
+ opt_servers= strdup(temp);
64
+ else
65
+ {
66
+ fprintf(stderr, "No Servers provided\n\n");
67
+ help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, 0);
68
+ exit(1);
69
+ }
70
+ }
71
+
72
+ memc= memcached_create(NULL);
73
+
74
+ servers= memcached_servers_parse(opt_servers);
75
+ memcached_server_push(memc, servers);
76
+ memcached_server_list_free(servers);
77
+
78
+ memc_stat= memcached_stat(memc, NULL, &rc);
79
+
80
+ if (rc != MEMCACHED_SUCCESS && rc != MEMCACHED_SOME_ERRORS)
81
+ {
82
+ printf("Failure to communicate with servers (%s)\n",
83
+ memcached_strerror(memc, rc));
84
+ exit(1);
85
+ }
86
+
87
+ server_list= memcached_server_list(memc);
88
+
89
+ if (opt_analyze)
90
+ run_analyzer(memc, memc_stat, server_list);
91
+ else
92
+ print_server_listing(memc, memc_stat, server_list);
93
+
94
+ free(memc_stat);
95
+ free(opt_servers);
96
+
97
+ memcached_free(memc);
98
+
99
+ return 0;
100
+ }
101
+
102
+ static void run_analyzer(memcached_st *memc, memcached_stat_st *memc_stat,
103
+ memcached_server_st *server_list)
104
+ {
105
+ memcached_return rc;
106
+
107
+ if (analyze_mode == NULL)
108
+ {
109
+ memcached_analysis_st *report;
110
+ report= memcached_analyze(memc, memc_stat, &rc);
111
+ if (rc != MEMCACHED_SUCCESS || report == NULL)
112
+ {
113
+ printf("Failure to analyze servers (%s)\n",
114
+ memcached_strerror(memc, rc));
115
+ exit(1);
116
+ }
117
+ print_analysis_report(memc, report, server_list);
118
+ free(report);
119
+ }
120
+ else if (strcmp(analyze_mode, "latency") == 0)
121
+ {
122
+ memcached_st **servers;
123
+ uint32_t x, y, flags, server_count= memcached_server_count(memc);
124
+ uint32_t num_of_tests= 32;
125
+ const char *test_key= "libmemcached_test_key";
126
+
127
+ servers= malloc(sizeof(memcached_st*) * server_count);
128
+ if (!servers)
129
+ {
130
+ fprintf(stderr, "Failed to allocate memory\n");
131
+ return;
132
+ }
133
+
134
+ for (x= 0; x < server_count; x++)
135
+ {
136
+ if((servers[x]= memcached_create(NULL)) == NULL)
137
+ {
138
+ fprintf(stderr, "Failed to memcached_create()\n");
139
+ if (x > 0)
140
+ memcached_free(servers[0]);
141
+ x--;
142
+ for (; x > 0; x--)
143
+ memcached_free(servers[x]);
144
+
145
+ free(servers);
146
+ return;
147
+ }
148
+ memcached_server_add(servers[x],
149
+ memcached_server_name(memc, server_list[x]),
150
+ memcached_server_port(memc, server_list[x]));
151
+ }
152
+
153
+ printf("Network Latency Test:\n\n");
154
+ struct timeval start_time, end_time;
155
+ long elapsed_time, slowest_time= 0, slowest_server= 0;
156
+
157
+ for (x= 0; x < server_count; x++)
158
+ {
159
+ gettimeofday(&start_time, NULL);
160
+ for (y= 0; y < num_of_tests; y++)
161
+ {
162
+ size_t vlen;
163
+ char *val= memcached_get(servers[x], test_key, strlen(test_key),
164
+ &vlen, &flags, &rc);
165
+ if (rc != MEMCACHED_NOTFOUND && rc != MEMCACHED_SUCCESS)
166
+ break;
167
+ free(val);
168
+ }
169
+ gettimeofday(&end_time, NULL);
170
+
171
+ elapsed_time= timedif(end_time, start_time);
172
+ elapsed_time /= (long)num_of_tests;
173
+
174
+ if (elapsed_time > slowest_time)
175
+ {
176
+ slowest_server= (long)x;
177
+ slowest_time= elapsed_time;
178
+ }
179
+
180
+ if (rc != MEMCACHED_NOTFOUND && rc != MEMCACHED_SUCCESS)
181
+ {
182
+ printf("\t %s (%d) => failed to reach the server\n",
183
+ memcached_server_name(memc, server_list[x]),
184
+ memcached_server_port(memc, server_list[x]));
185
+ }
186
+ else
187
+ {
188
+ printf("\t %s (%d) => %ld.%ld seconds\n",
189
+ memcached_server_name(memc, server_list[x]),
190
+ memcached_server_port(memc, server_list[x]),
191
+ elapsed_time / 1000, elapsed_time % 1000);
192
+ }
193
+ }
194
+
195
+ if (server_count > 1 && slowest_time > 0)
196
+ {
197
+ printf("---\n");
198
+ printf("Slowest Server: %s (%d) => %ld.%ld seconds\n",
199
+ memcached_server_name(memc, server_list[slowest_server]),
200
+ memcached_server_port(memc, server_list[slowest_server]),
201
+ slowest_time / 1000, slowest_time % 1000);
202
+ }
203
+ printf("\n");
204
+
205
+ for (x= 0; x < server_count; x++)
206
+ memcached_free(servers[x]);
207
+
208
+ free(servers);
209
+ free(analyze_mode);
210
+ }
211
+ else
212
+ {
213
+ fprintf(stderr, "Invalid Analyzer Option provided\n");
214
+ free(analyze_mode);
215
+ }
216
+ }
217
+
218
+ static void print_server_listing(memcached_st *memc, memcached_stat_st *memc_stat,
219
+ memcached_server_st *server_list)
220
+ {
221
+ unsigned int x;
222
+ memcached_return rc;
223
+
224
+ printf("Listing %u Server\n\n", memcached_server_count(memc));
225
+ for (x= 0; x < memcached_server_count(memc); x++)
226
+ {
227
+ char **list;
228
+ char **ptr;
229
+
230
+ list= memcached_stat_get_keys(memc, &memc_stat[x], &rc);
231
+
232
+ printf("Server: %s (%u)\n", memcached_server_name(memc, server_list[x]),
233
+ memcached_server_port(memc, server_list[x]));
234
+ for (ptr= list; *ptr; ptr++)
235
+ {
236
+ char *value= memcached_stat_get_value(memc, &memc_stat[x], *ptr, &rc);
237
+
238
+ printf("\t %s: %s\n", *ptr, value);
239
+ free(value);
240
+ }
241
+
242
+ free(list);
243
+ printf("\n");
244
+ }
245
+ }
246
+
247
+ static void print_analysis_report(memcached_st *memc,
248
+ memcached_analysis_st *report,
249
+ memcached_server_st *server_list)
250
+ {
251
+ uint32_t server_count= memcached_server_count(memc);
252
+
253
+ printf("Memcached Cluster Analysis Report\n\n");
254
+
255
+ printf("\tNumber of Servers Analyzed : %d\n", server_count);
256
+ printf("\tAverage Item Size (incl/overhead) : %u bytes\n",
257
+ report->average_item_size);
258
+
259
+ if (server_count == 1)
260
+ {
261
+ printf("\nFor a detailed report, you must supply multiple servers.\n");
262
+ return;
263
+ }
264
+
265
+ printf("\n");
266
+ printf("\tNode with most memory consumption : %s:%u (%llu bytes)\n",
267
+ memcached_server_name(memc, server_list[report->most_consumed_server]),
268
+ memcached_server_port(memc, server_list[report->most_consumed_server]),
269
+ (unsigned long long)report->most_used_bytes);
270
+ printf("\tNode with least free space : %s:%u (%llu bytes remaining)\n",
271
+ memcached_server_name(memc, server_list[report->least_free_server]),
272
+ memcached_server_port(memc, server_list[report->least_free_server]),
273
+ (unsigned long long)report->least_remaining_bytes);
274
+ printf("\tNode with longest uptime : %s:%u (%us)\n",
275
+ memcached_server_name(memc, server_list[report->oldest_server]),
276
+ memcached_server_port(memc, server_list[report->oldest_server]),
277
+ report->longest_uptime);
278
+ printf("\tPool-wide Hit Ratio : %1.f%%\n", report->pool_hit_ratio);
279
+ printf("\n");
280
+ }
281
+
282
+ static void options_parse(int argc, char *argv[])
283
+ {
284
+ memcached_programs_help_st help_options[]=
285
+ {
286
+ {0},
287
+ };
288
+
289
+ int option_index= 0;
290
+ int option_rv;
291
+
292
+ while (1)
293
+ {
294
+ option_rv= getopt_long(argc, argv, "Vhvds:a", long_options, &option_index);
295
+ if (option_rv == -1) break;
296
+ switch (option_rv)
297
+ {
298
+ case 0:
299
+ break;
300
+ case OPT_VERBOSE: /* --verbose or -v */
301
+ opt_verbose = OPT_VERBOSE;
302
+ break;
303
+ case OPT_DEBUG: /* --debug or -d */
304
+ opt_verbose = OPT_DEBUG;
305
+ break;
306
+ case OPT_VERSION: /* --version or -V */
307
+ version_command(PROGRAM_NAME);
308
+ break;
309
+ case OPT_HELP: /* --help or -h */
310
+ help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, help_options);
311
+ break;
312
+ case OPT_SERVERS: /* --servers or -s */
313
+ opt_servers= strdup(optarg);
314
+ break;
315
+ case OPT_ANALYZE: /* --analyze or -a */
316
+ opt_analyze= OPT_ANALYZE;
317
+ analyze_mode= (optarg) ? strdup(optarg) : NULL;
318
+ break;
319
+ case '?':
320
+ /* getopt_long already printed an error message. */
321
+ exit(1);
322
+ default:
323
+ abort();
324
+ }
325
+ }
326
+ }