diff options
author | antirez <antirez@gmail.com> | 2015-09-23 16:46:36 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2015-10-01 13:02:25 +0200 |
commit | 9253d8507320dd1d7665a55e11e2cba3ae91c78d (patch) | |
tree | 305ccd34924ae2860cd5aec9788c3007621661fa /src/lazyfree.c | |
parent | 4d50d691e3fa80c9b9aef5aa0498a0a92654b324 (diff) | |
download | redis-9253d8507320dd1d7665a55e11e2cba3ae91c78d.tar.gz |
Threaded lazyfree WIP #1.
Diffstat (limited to 'src/lazyfree.c')
-rw-r--r-- | src/lazyfree.c | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/lazyfree.c b/src/lazyfree.c index 84d4b3752..27f9a56e9 100644 --- a/src/lazyfree.c +++ b/src/lazyfree.c @@ -1,4 +1,7 @@ #include "server.h" +#include "bio.h" + +static int lazyfree_threaded = 1; /* Use a thread to reclaim objects. */ /* Initialization of the lazy free engine. Must be called only once at server * startup. */ @@ -97,7 +100,17 @@ size_t lazyfreeFastStep(void) { /* Handles slow or fast collection steps. */ size_t lazyfreeStep(int type) { - if (type == LAZYFREE_STEP_FAST) return lazyfreeFastStep(); + /* Threaded implementaiton: only block for STEP_OOM. */ + if (lazyfree_threaded) { + if (type == LAZYFREE_STEP_OOM) + return bioWaitStepOfType(BIO_LAZY_FREE); + return 0; + } + + /* Non threaded implementation: free things incrementally avoiding + * to block. */ + if (type == LAZYFREE_STEP_FAST || + type == LAZYFREE_STEP_OOM) return lazyfreeFastStep(); size_t totalwork = 0; mstime_t end = mstime()+2; @@ -130,8 +143,12 @@ int dbAsyncDelete(redisDb *db, robj *key) { /* If releasing the object is too much work, let's put it into the * lazy free list. */ if (free_effort > LAZYFREE_THRESHOLD) { - listAddNodeTail(server.lazyfree_obj,val); - server.lazyfree_elements += free_effort; + if (lazyfree_threaded) { + bioCreateBackgroundJob(BIO_LAZY_FREE,val,NULL,NULL); + } else { + listAddNodeTail(server.lazyfree_obj,val); + server.lazyfree_elements += free_effort; + } dictSetVal(db->dict,de,NULL); } } @@ -165,6 +182,9 @@ int lazyfreeCron(struct aeEventLoop *eventLoop, long long id, void *clientData) UNUSED(id); UNUSED(clientData); + /* Threaded lazy free does not need a timer, unregister the timer event. */ + if (lazyfree_threaded) return AE_NOMORE; + static size_t prev_mem; static int timer_period = 1000; /* Defauls to 1HZ */ static double mem_trend = 0; |