Skip to content

Instantly share code, notes, and snippets.

@StephanDollberg
Last active September 30, 2016 13:25
Show Gist options
  • Save StephanDollberg/d065c9f4ae8c7906b0624402a840c7a9 to your computer and use it in GitHub Desktop.
Save StephanDollberg/d065c9f4ae8c7906b0624402a840c7a9 to your computer and use it in GitHub Desktop.
twemproxy bench / DO 8 core machine
./clients/memslap -s 127.0.0.1:11211/20000 -S 5s -T 4 -c 200
twemcache direct
Get Statistics
Type Time(s) Ops TPS(ops/s) Net(M/s) Get_miss Min(us) Max(us) Avg(us) Std_dev Geo_dist
Period 5 637239 127447 132.2 143267 70 27985 1406 966.24 1239.16
Global 5 637239 127447 132.2 143268 70 27985 1406 966.24 1239.16
Set Statistics
Type Time(s) Ops TPS(ops/s) Net(M/s) Get_miss Min(us) Max(us) Avg(us) Std_dev Geo_dist
Period 5 70912 14182 14.7 0 124 27971 1423 1072.03 1243.67
Global 5 70912 14182 14.7 0 124 27971 1423 1072.03 1243.67
Total Statistics
Type Time(s) Ops TPS(ops/s) Net(M/s) Get_miss Min(us) Max(us) Avg(us) Std_dev Geo_dist
Period 5 708163 141632 147.0 143271 70 27985 1408 976.92 1239.61
Global 5 708163 >>> 141632 147.0 143271 70 27985 1408 976.92 1239.61
twemproxy / 1 core
Get Statistics
Type Time(s) Ops TPS(ops/s) Net(M/s) Get_miss Min(us) Max(us) Avg(us) Std_dev Geo_dist
Period 5 190735 38147 38.7 44985 128 16413 4717 1052.84 4608.93
Global 10 372860 37286 39.6 53474 128 17195 4824 1147.81 4700.51
Set Statistics
Type Time(s) Ops TPS(ops/s) Net(M/s) Get_miss Min(us) Max(us) Avg(us) Std_dev Geo_dist
Period 5 21187 4237 4.3 0 217 15788 4700 1033.07 4593.68
Global 10 41524 4152 4.4 0 217 15788 4801 1143.12 4678.18
Total Statistics
Type Time(s) Ops TPS(ops/s) Net(M/s) Get_miss Min(us) Max(us) Avg(us) Std_dev Geo_dist
Period 5 211924 42384 43.0 44986 128 16413 4716 1047.75 4607.41
Global 10 414386 >>> 41438 44.0 53475 128 17195 4821 1150.28 4698.27
twemproxy / 5 cores
Get Statistics
Type Time(s) Ops TPS(ops/s) Net(M/s) Get_miss Min(us) Max(us) Avg(us) Std_dev Geo_dist
Period 5 549634 109926 109.5 512044 0 50720 1632 1963.94 1098.71
Global 75 7917489 105566 114.1 6269354 0 89138 1697 2087.01 1107.12
Set Statistics
Type Time(s) Ops TPS(ops/s) Net(M/s) Get_miss Min(us) Max(us) Avg(us) Std_dev Geo_dist
Period 5 61068 12213 12.2 0 76 48600 1628 1965.35 1097.12
Global 75 879820 11730 12.7 0 0 84867 1696 2085.73 1107.59
Total Statistics
Type Time(s) Ops TPS(ops/s) Net(M/s) Get_miss Min(us) Max(us) Avg(us) Std_dev Geo_dist
Period 5 610715 122143 121.7 512050 0 50720 1632 1963.73 1098.54
Global 75 8797323 >>> 117297 126.7 6269358 0 89138 1697 2086.80 1107.17
From 2236f0d8570a27254804557bab9f11bb77a7e6e3 Mon Sep 17 00:00:00 2001
From: Stephan Dollberg <[email protected]>
Date: Thu, 29 Sep 2016 19:04:36 +0100
Subject: [PATCH] processified
---
src/nc.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
src/nc_proxy.c | 7 +++++++
src/nc_stats.c | 7 +++++++
3 files changed, 59 insertions(+)
diff --git a/src/nc.c b/src/nc.c
index bde044c..a669b01 100644
--- a/src/nc.c
+++ b/src/nc.c
@@ -536,6 +536,49 @@ nc_run(struct instance *nci)
core_stop(ctx);
}
+#include <sys/wait.h>
+void nc_fork_workers(void);
+
+
+void nc_fork_workers(void) {
+ int workers = 5;
+
+ int i = 0;
+ // spawn initial worker set
+ for (i = 0; i < workers; i++) {
+ pid_t worker_pid = fork();
+
+ if (worker_pid == -1) {
+ fprintf(stderr, "can't fork");
+ exit(1);
+ }
+
+ if (worker_pid == 0) {
+ return;
+ }
+ }
+
+
+ // wait for children and restart workers
+ while (1) {
+ int status = 0;
+ int pid = waitpid(-1, &status, 0);
+
+ fprintf(stderr, "worker died: %d\n", pid);
+
+ pid_t worker_pid = fork();
+
+ if (worker_pid == -1) {
+ fprintf(stderr, "can't fork");
+ exit(1);
+ }
+
+ if (worker_pid == 0) {
+ return;
+ }
+ }
+}
+
int
main(int argc, char **argv)
{
@@ -570,6 +613,8 @@ main(int argc, char **argv)
exit(0);
}
+ nc_fork_workers();
+
status = nc_pre_run(&nci);
if (status != NC_OK) {
nc_post_run(&nci);
diff --git a/src/nc_proxy.c b/src/nc_proxy.c
index 38cdd9e..9570dc2 100644
--- a/src/nc_proxy.c
+++ b/src/nc_proxy.c
@@ -142,6 +142,13 @@ proxy_listen(struct context *ctx, struct conn *p)
return NC_ERROR;
}
+ // should probably be in proxy_reuse
+ int enable = 1;
+ if (setsockopt(p->sd, SOL_SOCKET, SO_REUSEPORT, &enable, sizeof(enable)) < 0) {
+ log_error("failed to set reuseport");
+ return NC_ERROR;
+ }
+
status = bind(p->sd, p->addr, p->addrlen);
if (status < 0) {
log_error("bind on p %d to addr '%.*s' failed: %s", p->sd,
diff --git a/src/nc_stats.c b/src/nc_stats.c
index fa4d92c..c0f24bd 100644
--- a/src/nc_stats.c
+++ b/src/nc_stats.c
@@ -834,6 +834,13 @@ stats_listen(struct stats *st)
return NC_ERROR;
}
+ // doesn't really make sense for stats but makes it work for now
+ int enable = 1;
+ if (setsockopt(st->sd, SOL_SOCKET, SO_REUSEPORT, &enable, sizeof(enable)) < 0) {
+ log_error("failed to set reuseport");
+ return NC_ERROR;
+ }
+
status = bind(st->sd, (struct sockaddr *)&si.addr, si.addrlen);
if (status < 0) {
log_error("bind on m %d to addr '%.*s:%u' failed: %s", st->sd,
--
2.1.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment