summaryrefslogtreecommitdiff
path: root/thread.c
diff options
context:
space:
mode:
authordormando <dormando@rydia.net>2020-02-25 18:09:05 -0800
committerdormando <dormando@rydia.net>2020-02-26 00:16:50 -0800
commit05721e4b6c393f25830021bb13f6637e5747dfcc (patch)
tree533ac96420a55842798070ee225a4ca32d39febc /thread.c
parent379e3df46dd2f08fb12f577bba70a9d7422b6f7c (diff)
downloadmemcached-05721e4b6c393f25830021bb13f6637e5747dfcc.tar.gz
add separate limits for connection buffers
allows specifying a megabyte limit for either response objects or read buffers. this is split among all of the worker threads. useful if connection limit is extremely high and you want to aggressively close connections if something happens and all connections become active at the same time. missing runtime tuning.
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/thread.c b/thread.c
index 2b91f3e..ebb0379 100644
--- a/thread.c
+++ b/thread.c
@@ -411,12 +411,32 @@ static void setup_thread(LIBEVENT_THREAD *me) {
fprintf(stderr, "Failed to create response cache\n");
exit(EXIT_FAILURE);
}
+ // Note: we were cleanly passing in num_threads before, but this now
+ // relies on settings globals too much.
+ if (settings.resp_obj_mem_limit) {
+ int limit = settings.resp_obj_mem_limit / settings.num_threads;
+ if (limit < sizeof(mc_resp)) {
+ limit = 1;
+ } else {
+ limit = limit / sizeof(mc_resp);
+ }
+ cache_set_limit(me->resp_cache, limit);
+ }
me->rbuf_cache = cache_create("rbuf", READ_BUFFER_SIZE, sizeof(char *), NULL, NULL);
if (me->rbuf_cache == NULL) {
fprintf(stderr, "Failed to create read buffer cache\n");
exit(EXIT_FAILURE);
}
+ if (settings.read_buf_mem_limit) {
+ int limit = settings.read_buf_mem_limit / settings.num_threads;
+ if (limit < READ_BUFFER_SIZE) {
+ limit = 1;
+ } else {
+ limit = limit / READ_BUFFER_SIZE;
+ }
+ cache_set_limit(me->rbuf_cache, limit);
+ }
#ifdef EXTSTORE
me->io_cache = cache_create("io", sizeof(io_wrap), sizeof(char*), NULL, NULL);