-
Notifications
You must be signed in to change notification settings - Fork 183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to best implement asynchronous responses #131
Comments
Related: #27 |
Thanks @laf0rge , you surely pointed out a new bug. My intention is to have Ulfius multi-threaded by default. Lately I changed the options in I thought that I will reuse |
This should be fixed in the master branch now, can you validate the new behavior with the threads? |
By the way, according to this message, But I don't see in the documentation where My best guess is that when you use threads, by default MHD uses a thread pool size according to the underlying system. |
You don't must use it. You just get only a single thread unless you specify it. from libmicrohttpd.texi:
unfortunately it doesn't seem like that. MHD_OPTION_THREAD_POOL_SIZE is the only place in the libmicrohttpd source that I can find where daemon->worker_pool_size is set to a value > 1. But in any case, now that you reverted back to MHD_USE_THREAD_PER_CONNECTION (which was the default up and including to ulfius 2.5.2, for the record) I guess that particular discussion doesn't make any difference. I'll need some time to actually develop the code that uses libulfius with pthread_cond_wait() in the callback, but I'll report back about any progress or issues. |
No problem, I'll wait for your feedback then, thanks |
Hello @laf0rge , I asked upstream the question about the connection between So if one uses Therefore, I think I will add an option in Ulfius 2.7 to choose between |
Hi @babelouest I try to use the library in my project. Everything is good for me. However, I cannot change I would like to use only one thread in my application as below:
If I can control Let me know if there is other way for this. Thank you for providing this great library. |
Maybe a solution for this is to allow to update the The internal function ulfius_run_mhd_daemon runs Instead of building the Most users wouldn't have to use these functions because Ulfius' default settings are good enough for most use cases, but power users could change the default settings at will. How about that? |
Ah! It's my mistake. I can create my own MDH_Daemon instance before calling ulfius_start_framework() function. In this case, my application can use my own thread with an asynchronous way. Thank you for your suggestion. |
You could do that, instead of calling Although I don't recommend to bypass internal libraries functionalities, there could be unknown side effects or breaking changes in future versions. But it's your decision. |
There is one more question regarding this issue. In sheep_example, My apologies if I was misunderstanding. |
@acetcom , there is no mutex in the It's just a simple example to basically show how JSON parameters can be used in a REST API solution. |
@babelouest Ok! No Problem. |
I've made a new function |
Hi @babelouest My project has not only REST API but also other protocols. So I had to organize all of these into only one event-loop thread. And also, I needed microhttpd flow control. At that time, I realized that it was difficult to use ulfius for this purpose. And I re-implemented this part in my own way. Let me share the microhttpd wrapper as below. https://github.com/open5gs/open5gs/blob/sbi/lib/sbi/server.h I hope that it could help improve ulfius. Thank you for considering it. |
No problem, but the functionality was asked by other people and may be useful to other. Happy hacking! |
@babelouest Thanks for doing a great job and sharing it with the community! We've been using ulfius for a while now and as we started doing some stress testing of our API we realised that Are there any estimates for when the next release is coming out so that we can take this new feature for a spin? |
Hello @IvanRibakov , Ulfius 2.6.7 will be release soon, hopefully. |
Hello @IvanRibakov , Ulfius 2.6.7 has just been released with the new features, happy hacking! |
I couldn't find any forum or mailing list, so I'm filing an issue here. It's neither a bug report nor a feature request, my apologies if this is not appropriate here.
Let's say I have a (rather complex) single-threaded, event-loop driven program and I would like to add a REST API to it, preferably using ulfius. I've been brainstorming about how to do this properly.
The way how ulfius uses microhttpd (at least with modern libmicrohttpd) is to ask microhttpd to start only one thread and handle all incoming HTTP connections within that thread. At least after reading MHD source code, this is what MHD_USE_INTERNAL_POLLING_THREAD without MHD_OPTION_THREAD_POOL_SIZE appears to be doing. There's of course nothing wrong with that, but then ulfius appears to require a "synchronous" (i.e. instantaneous, non-deferred) response to be generated by the callback for a given REST API enpdoint.
This means I cannot e.g. dispatch a message to my main thread from that endpoint callback function, and pthread_cond_wait() for the main thread to process whatever it needs to do before generating a response. If I did that, I would be making the single HTTP thread of MHD to block, i.e. not process any other HTTP requests until the main thread completes. For fast responses, that might work, but for longer responses (e.g. the main thread first having to communicate with a number of other entities over various network protocols before having a response) this is not feasible.
Is three anything I'm missing? Is there any other way to asynchronously build the response?
I think if there is no other way to deal with such situations, starting microhttpd with MHD_USE_THREAD_PER_CONNECTION is one way to resolve the above issue. In this case, only the thread related to one HTTP client would block on the above-mentioned pthread_cond_wait(), while others could operate concurrently. But ulfius doesn't provide any option to do so, it will only do that unconditionally with old microhttpd versions.
The text was updated successfully, but these errors were encountered: