The effects of signal() in a multithreaded process are unspecified.
--
You received this message because you are subscribed to the Google Groups "onion-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to onion-dev+unsubscribe@coralbits.com.
To post to this group, send email to onio...@coralbits.com.
Visit this group at https://groups.google.com/a/coralbits.com/group/onion-dev/.
For more options, visit https://groups.google.com/a/coralbits.com/d/optout.
On 2018-07-03 15:10, David Moreno Montero wrote:
If there are several onion_new the developer should write a custom
sigterm handler that does cannot each onion_stop_listen for each
onion*. To help a bit, onion_stop_listen function should be signal
friendly, so that it can just be called from a signal handler.
But that makes a huge difference.
My feeling is to use the pipe to self trick (explained in http://doc.qt.io/qt-5/unix-signals.html for Qt, but we can adapt that to Onion).
Then, the signal handler justs writes into a pipe (this is ok and async-signal-safe) and the Onion event handler handles that pipe appropriately. So onion_listen_stop is not called from the signal handler (but from the event loop) and that is async-signal-safe.
If we have several event loops (that is several onion_new) that scheme won't work reliably.
I believe that we should not care about several onion_new, and document that only one instance of onion_new is expected.
This is the practice in GTK (only one X11 display handled) and in Qt (only one QApplication instance).
But we need to decide if we can afford requiring only one instance of onion_new.
My vote is of course yes!
Hi,
I think we all share the same basic ideas, so its perfect if you can work on it Basile. Thanks!
I did read the caveats section, and it's ok, but I'm only wondering why you say onion is not c10k ready, not that that was a explicit goal, but load tests are quite good: 138k req/s using keep alive and 20 concurrent connections, 20k no keep alive (on an above average i7).
BTW, I don't know much about HTTP. If you have some guidelines about it (such as concrete figures about how many HTTP connections a modern web browser like a recent firefox or chrome is making), I would be very happy to know them. Any clues about web development is welcome. BTW, in my eyes, ocsigen is very inspirational (as an approach to web development), much more than e.g. old PHP.
BTW I would be delighted to have some concrete things about your usage and also usage by other readers of onion-dev of libonion. (e.g. the actual use case, hardware, number of requests per second, number of connections per second, data volume, common HTTP requests, ...). If you can share them (perhaps on some blog) I would be extremely happy! (even if your applications using libonion are not free software).
First, SIGTERM handling makes only sense with one single onion object (that is a single call to onion_new happening at initialization time). I really believe there is no way to handle SIGTERM safely and reliably in an arbitrary case of several onion instances created and managed in independent threads. BTW, so far, nobody gave any use case of several onion instances. So that case is really uncommon (and honestly, I don't think that libonion has been well tested in that general case). BTW, for the particular case of a single onion, I suggest also having some
/*** @short Gives the only single instance of onion.* Usable only if you are sure to call `onion_new` once. Don't use that to check that you do use `onion_new` once.* \b{undefined} when you call `onion_new` several times.* @ingroup onion*/onion* onion_single_instance (void);
% make
[ 14%] Built target onion_static
[ 28%] Built target onion
[ 29%] Built target onion_extras
[ 31%] Built target onioncpp_static
[ 34%] Built target onioncpp
[ 38%] Built target opack
[ 38%] Built target crl
[ 38%] Linking C executable otemplate
/usr/bin/ld: CMakeFiles/otemplate.dir/__/__/src/onion/log.c.o: in function `onion_log_stderr':
log.c:(.text+0x7f): undefined reference to `pthread_once'
/usr/bin/ld: CMakeFiles/otemplate.dir/__/__/src/onion/dict.c.o: in function `onion_dict_new':
dict.c:(.text+0x13a): undefined reference to `pthread_rwlock_init'
/usr/bin/ld: CMakeFiles/otemplate.dir/__/__/src/onion/dict.c.o: in function `onion_dict_free':
dict.c:(.text+0x1ed): undefined reference to `pthread_rwlock_destroy'
/usr/bin/ld: CMakeFiles/otemplate.dir/__/__/src/onion/dict.c.o: in function `onion_dict_lock_read':
dict.c:(.text+0xc35): undefined reference to `pthread_rwlock_rdlock'
/usr/bin/ld: CMakeFiles/otemplate.dir/__/__/src/onion/dict.c.o: in function `onion_dict_lock_write':
dict.c:(.text+0xc45): undefined reference to `pthread_rwlock_wrlock'
/usr/bin/ld: CMakeFiles/otemplate.dir/__/__/src/onion/dict.c.o: in function `onion_dict_unlock':
dict.c:(.text+0xc55): undefined reference to `pthread_rwlock_unlock'
/usr/bin/ld: CMakeFiles/otemplate.dir/__/__/src/onion/low.c.o:(.data.rel+0x0): undefined reference to `pthread_sigmask'
/usr/bin/ld: CMakeFiles/otemplate.dir/__/__/src/onion/low.c.o:(.data.rel+0x10): undefined reference to `pthread_detach'
/usr/bin/ld: CMakeFiles/otemplate.dir/__/__/src/onion/low.c.o:(.data.rel+0x18): undefined reference to `pthread_cancel'
/usr/bin/ld: CMakeFiles/otemplate.dir/__/__/src/onion/low.c.o:(.data.rel+0x20): undefined reference to `pthread_join'
/usr/bin/ld: CMakeFiles/otemplate.dir/__/__/src/onion/low.c.o:(.data.rel+0x28): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
make[2]: *** [tools/otemplate/CMakeFiles/otemplate.dir/build.make:279: tools/otemplate/otemplate] Error 1
make[1]: *** [CMakeFiles/Makefile2:559: tools/otemplate/CMakeFiles/otemplate.dir/all] Error 2
make: *** [Makefile:152: all] Error 2
About the cmake error, I think you can apply the attached patch.
Basically the main problem is that pthread is now required, even for otempleate, which did not require it before.
About the code, looks good, but I would change some things.
1. The signal fds, should be stored at the onion struct, and the poller handler always installed. This would allow to stop it even from other non signal scenarios, using these pipe. It should be closed at onion_free as well.
2. So the install_sigterm_processing_onion (better onion_install_sigterm) would only add the signals, not deal with any pipe related.3. The function comments, should better follow the standard on other functions: /// if only one line, "/* @short" and so on if several.
4. If the functions are not to be exported, mark them "static" and they will not pollute the global scope, which in C is quite easy to pollute. And they may be inlined and optimized (byte_to_signum).
5. Function names, I would prefer, but you are the boss:signal_poll_pipe_routine -> onion_manage_eventinstall_sigterm_processing_onion -> onion_sigterm_install6. In another email you asked about the private date for epoll handlers; you can pass onion itself as the data for this poller, si that it can grab from it the pipe read fd, and do whatever is necessary to stop onion.
At last, I need to use onion_poller_slot_new but I feel that its function argument (the second one, function pointer f) is not well documented. It seems to be (for a read polling) some kind of reading function, but I am surprised it does not get (also) the file descriptor to read (so I would expect that argument to be declared int (*f) (int fd, void*clientdata), not int (*f) (void*). Why is it so? Also, I am guessing that it returns the number of read bytes on success, and -1 on read failure. Is my understanding correct?
1. The signal fds, should be stored at the onion struct, and the poller handler always installed. This would allow to stop it even from other non signal scenarios, using these pipe. It should be closed at onion_free as well.2. So the install_sigterm_processing_onion (better onion_install_sigterm) would only add the signals, not deal with any pipe related.
About the cmake error, I think you can apply the attached patch.
--
You received this message because you are subscribed to the Google Groups "onion-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to onion-dev+unsubscribe@coralbits.com.
To post to this group, send email to onio...@coralbits.com.
Visit this group at https://groups.google.com/a/coralbits.com/group/onion-dev/.
For more options, visit https://groups.google.com/a/coralbits.com/d/optout.
Can you try again to merge it with "git am FILENAME.patch". I just tried on your latest master and it applied cleanly
Hi,
the default handler will not work on the multi onion case, but a custom handler may know all the onion * handlers and send all the required signals through the pipe to all the onion*.
onion_poller_slot is an struct that stores all the data for the handler: callback, destructor and timeout. It must be created beforehand adding to the poller, as the struct must be fully populated before inserting it. When the appropriate event arrives (only read) it calls the callback with the private data. This private data must contain the fd handler and so on.