Merge lp:~vbernat/libmemcached/fix-memaslap-tps into lp:libmemcached

Proposed by Vincent Bernat
Status: Merged
Merged at revision: 1112
Proposed branch: lp:~vbernat/libmemcached/fix-memaslap-tps
Merge into: lp:libmemcached
Diff against target: 79 lines (+26/-1)
3 files modified
clients/ms_conn.c (+19/-1)
clients/ms_conn.h (+1/-0)
clients/ms_task.c (+6/-0)
To merge this branch: bzr merge lp:~vbernat/libmemcached/fix-memaslap-tps
Reviewer Review Type Date Requested Status
Tangent Trunk Pending
Review via email: mp+201298@code.launchpad.net

Description of the change

The `--tps` option is currently broken except for very large TPS. The first commit fixes that. The second commit allows the time passed sleeping to be removed from the various provided statistic timers. I still get higher response time than without `--tps` but I assume this is related to how we need to reenter the event loop once we get throttled.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'clients/ms_conn.c'
2--- clients/ms_conn.c 2013-02-23 10:17:33 +0000
3+++ clients/ms_conn.c 2014-01-11 20:02:01 +0000
4@@ -2473,7 +2473,7 @@
5 {
6 gettimeofday(&curr_time, NULL);
7 time_diff= ms_time_diff(&ms_thread->startup_time, &curr_time);
8- tps= (int64_t)(((task->get_opt + task->set_opt) / (uint64_t)time_diff) * 1000000);
9+ tps= (uint64_t)(task->get_opt + task->set_opt) * 1000000 / (uint64_t)time_diff;
10
11 /* current throughput is greater than expected throughput */
12 if (tps > ms_thread->thread_ctx->tps_perconn)
13@@ -2499,6 +2499,7 @@
14 || ((c->currcmd.cmd == CMD_SET) && (item->exp_time > 0)))
15 {
16 gettimeofday(&c->start_time, NULL);
17+ memset(&c->throttle_time, 0, sizeof(c->start_time));
18 if ((c->currcmd.cmd == CMD_SET) && (item->exp_time > 0))
19 {
20 /* record the current time */
21@@ -2509,6 +2510,22 @@
22
23
24 /**
25+ * used to update the throttle time of each operation
26+ *
27+ * @param c, pointer of the concurrency
28+ */
29+static void ms_update_throttle_time(ms_conn_t *c)
30+{
31+ if ((ms_setting.stat_freq > 0)
32+ && (c->throttle_time.tv_usec == 0)
33+ && (c->throttle_time.tv_sec ==0))
34+ {
35+ gettimeofday(&c->throttle_time, NULL);
36+ }
37+} /* ms_update_throttle_time */
38+
39+
40+/**
41 * run the state machine
42 *
43 * @param c, pointer of the concurrency
44@@ -2567,6 +2584,7 @@
45 case conn_write:
46 if (! c->ctnwrite && ms_need_yield(c))
47 {
48+ ms_update_throttle_time(c);
49 usleep(10);
50
51 if (! ms_update_event(c, EV_WRITE | EV_PERSIST))
52
53=== modified file 'clients/ms_conn.h'
54--- clients/ms_conn.h 2011-04-28 00:28:00 +0000
55+++ clients/ms_conn.h 2014-01-11 20:02:01 +0000
56@@ -192,6 +192,7 @@
57 /* response time statistic and time out control */
58 struct timeval start_time; /* start time of current operation(s) */
59 struct timeval end_time; /* end time of current operation(s) */
60+ struct timeval throttle_time; /* start time where we started throttling */
61
62 /* Binary protocol stuff */
63 protocol_binary_response_header binary_header; /* local temporary binary header */
64
65=== modified file 'clients/ms_task.c'
66--- clients/ms_task.c 2013-10-01 23:33:25 +0000
67+++ clients/ms_task.c 2014-01-11 20:02:01 +0000
68@@ -972,6 +972,12 @@
69
70 gettimeofday(&c->end_time, NULL);
71 uint64_t time_diff= (uint64_t)ms_time_diff(&c->start_time, &c->end_time);
72+ if ((c->throttle_time.tv_usec != 0)
73+ || (c->throttle_time.tv_sec != 0))
74+ {
75+ uint64_t throttle_time = (uint64_t)ms_time_diff(&c->throttle_time, &c->end_time);
76+ time_diff -= throttle_time;
77+ }
78
79 pthread_mutex_lock(&ms_statistic.stat_mutex);
80

Subscribers

People subscribed via source and target branches

to all changes: