New tarantool tx thread api #5641
Replies: 7 comments 8 replies
-
Since message passing would be implemented using queue, the following rules must apply:
|
Beta Was this translation helpful? Give feedback.
-
Module lifecycleThe main entry point for module spawning and configuration is Lua. Module should be aware of it's own threads lifetime, their startup and shutdown. Threads may be spawned or gracefully respawned inside module's Nevertheless, there is one unobvious point, that module author must be aware of: server shutdown. It is possible to implement this using on_shutdown trigger, but it is much better to provide C-level API for registering on_shutdown. So, first call we need is:
Of cource, we need both register and unregister interface and it may be implemented either with two separate functions or like in lua API: with one function, that accepts replacement pointer: void on_shutdown( void * , void (*handler)(void *), void (*handler)(void *));
on_shutdown( mod_ptr, my_stop_fn, NULL );
// register new handler to be called with mod_ptr
on_shutdown( mod_ptr, my_stop_fn, my_stop_fn );
// re-register same handler to be called with mod_ptr
on_shutdown( mod_ptr, my_new_stop_fn, my_stop_fn );
// re-register other handler to be called with mod_ptr
on_shutdown( mod_ptr, NULL, my_new_stop_fn );
// unregister handler my_new_stop_fn |
Beta Was this translation helpful? Give feedback.
-
Cross-thread messaging API (tx -> thread)For easy module authors experience I propose to include default and supported way for communication in direction tx → thread. Unified and eventloop independent interface, in this case, may be the following (prefix From tx side:
For throughtput optimisations we may consider 2 additional separate functions: From thread side: For eventloop independent monitoring of messages we need and
Upon notifiction on
It seems, that also we need Diagram for this process: |
Beta Was this translation helpful? Give feedback.
-
Cross-thread messaging API (thread -> tx)As and example diagram I'd provide simple connect-accepting module. The only required API function are
It may be efficient to check queue availability before some step, that produce message dispatching (like connection accepting), so additional helper function will be useful
And referring previous API (tx->thread) one may note, that we may use the same queue and API. So we may take From the side of TX message receival and function invocation may be hidden by tarantool own implementation |
Beta Was this translation helpful? Give feedback.
-
https://github.com/mechanik20051988/queue ссылка на репозиторий, где содержится пример реализации соответствующих функций без привязки к тарантулу. Еще потребуется реализовать функцию tx_msg_send, для отправки сообщения в поток tx. |
Beta Was this translation helpful? Give feedback.
-
API Draft, v3After an online discussion, we desided to take in action the following, layered API:
FlowsProducer-to-Consumer may act with 2 different flows: message transmission or function dispatch. For every kind of flow would be created a pair of functions: Producer functions
Consumer functions
LifecycleFor tracking of lifecycle we need void on_shutdown( void * , void (*handler)(void *), void (*handler)(void *));
// register new handler to be called with mod_ptr
on_shutdown( mod_ptr, my_stop_fn, NULL );
// re-register same handler to be called with mod_ptr
on_shutdown( mod_ptr, my_stop_fn, my_stop_fn );
// re-register other handler to be called with mod_ptr
on_shutdown( mod_ptr, my_new_stop_fn, my_stop_fn );
// unregister handler my_new_stop_fn
on_shutdown( mod_ptr, NULL, my_new_stop_fn ); |
Beta Was this translation helpful? Give feedback.
-
3c9bfb6 implement new module api |
Beta Was this translation helpful? Give feedback.
-
We add one data struct and two functions to public API in module.h
When a module wants to have done some work in tx thread, it creates
struct module_request
, fills it with its own function and data and passes it totx_msg_send
.tx_process_request
function (for this purpose we may see for thread safe queue in dpdk as i think).Lua module api and high level api described in https://hackmd.io/PUgnXG61TJGaA3uc1tXAqg
I think it would be good to add the following three functions and structure to the public api.
Thus, the logic of the work looks like this. The user types
module = require('module')
, then luaopen_module function called. The module registers its own functions using luaL_openlib and then call tarantool_register_module, to create module context in tarantool and insert it in module list. In this function, we pass a table of pointers of the main module functions.When user types module.cfg{} module check params and if it's ok, calls tarantool_start_module in order for tarantool to create a thread for the main module function and call inside this function start from module vtab.
When user want to stop module he types module.stop, then module calls tarantool_module_stop in order for tarantool to stop a main module thread.
I think if add this functions to public API we will be able to transfer all resource management of the module to tarantool.
If we do not do this, the module creator will have to implement quite complex work with fibers every time (for example, we can not stop module and wait it stopped in tx thread)
Here I want to add some points that we discussed at the last meeting with mons. We need to implement five function in our public module API.
I specified the function arguments as I see them now. I described the number of functions
and their purpose based on our discussion with Mons
Beta Was this translation helpful? Give feedback.
All reactions