summaryrefslogtreecommitdiff
path: root/runtest-moduleapi
diff options
context:
space:
mode:
authorOzan Tezcan <ozantezcan@gmail.com>2022-01-18 14:10:07 +0300
committerGitHub <noreply@github.com>2022-01-18 13:10:07 +0200
commit99ab4236afb210dc118fad892210b9fbb369aa8e (patch)
tree2a3bb0d6279f066261ba7660e3bd44262cd183ec /runtest-moduleapi
parent25e6d4d4597d6ca06503d5fa76af0e4e1b57302e (diff)
downloadredis-99ab4236afb210dc118fad892210b9fbb369aa8e.tar.gz
Add event loop support to the module API (#10001)
Modules can now register sockets/pipe to the Redis main thread event loop and do network operations asynchronously. Previously, modules had to maintain an event loop and another thread for asynchronous network operations. Also, if a module is calling API functions after doing some network operations, it had to synchronize its event loop thread's access with Redis main thread by locking the GIL, causing contention on the lock. After this commit, no synchronization is needed as module can operate in Redis main thread context. So, this commit may improve the performance for some use cases. Added three functions to the module API: * RedisModule_EventLoopAdd(int fd, int mask, RedisModuleEventLoopFunc func, void *user_data) * RedisModule_EventLoopDel(int fd, int mask) * RedisModule_EventLoopAddOneShot(RedisModuleEventLoopOneShotFunc func, void *user_data) - This function can be called from other threads to trigger callback on Redis main thread. Callback will be triggered only once. If Redis main thread is sleeping, this call will wake up the Redis main thread. Event loop callbacks are called by Redis main thread after locking the GIL. Inside callbacks, modules can operate as if they are holding the GIL. Added REDISMODULE_EVENT_EVENTLOOP event with two subevents: * REDISMODULE_SUBEVENT_EVENTLOOP_BEFORE_SLEEP * REDISMODULE_SUBEVENT_EVENTLOOP_AFTER_SLEEP These events are for modules that want to participate in the before and after sleep action. e.g It might be useful to implement batching : Read data from the network, write all to a file in one go on BEFORE_SLEEP event.
Diffstat (limited to 'runtest-moduleapi')
-rwxr-xr-xruntest-moduleapi1
1 files changed, 1 insertions, 0 deletions
diff --git a/runtest-moduleapi b/runtest-moduleapi
index 652a563a6..8b4b108de 100755
--- a/runtest-moduleapi
+++ b/runtest-moduleapi
@@ -44,5 +44,6 @@ $TCLSH tests/test_helper.tcl \
--single unit/moduleapi/aclcheck \
--single unit/moduleapi/subcommands \
--single unit/moduleapi/reply \
+--single unit/moduleapi/eventloop \
"${@}"