Discussion:
[libmicrohttpd] Question on Async support
Santos Das
2018-08-23 16:21:41 UTC
Permalink
Hi,

Can anyone please confirm if libmicrohttpd supports the Async handling?

Also, any information on the performance of libmicrohttps will be useful.

thanks, santos
Christian Grothoff
2018-08-23 18:28:14 UTC
Permalink
Post by Santos Das
Hi,
Can anyone please confirm if libmicrohttpd supports the Async handling?
Yes, it supports asynchronous processing.
Post by Santos Das
Also, any information on the performance of libmicrohttps will be useful.
Let's just say if used properly, it will never be anywhere near the
bottleneck. We know people running 100,000 requests/s on a single system
with MHD years ago. Quite likely to do more today, but very difficult to
test: when benchmarking, you will always be benchmarking your clients,
your network or your application logic long before hitting any MHD
threshold (on sane operating systems).
Santos Das
2018-08-23 18:36:39 UTC
Permalink
Hi,

Thank you for the quick reply. I have one more question, please help in
clarifying -

Can "libmicrohttpd" run as a part of the application event loop or is
it *mandatory
*for the "libmicrohttpd" to have its own event loop?

thanks, santos
Post by Christian Grothoff
Post by Santos Das
Hi,
Can anyone please confirm if libmicrohttpd supports the Async handling?
Yes, it supports asynchronous processing.
Post by Santos Das
Also, any information on the performance of libmicrohttps will be useful.
Let's just say if used properly, it will never be anywhere near the
bottleneck. We know people running 100,000 requests/s on a single system
with MHD years ago. Quite likely to do more today, but very difficult to
test: when benchmarking, you will always be benchmarking your clients,
your network or your application logic long before hitting any MHD
threshold (on sane operating systems).
silvioprog
2018-08-23 18:45:14 UTC
Permalink
Hello Santos.

Yes, you can use your own main loop. Please see:

"*The fourth threading model (used when no specific flag is given), uses no
threads. Instead, the main application must (periodically) request file
descriptor sets from MHD, perform a select call and then call MHD_run.
MHD_run will then process HTTP requests as usual and return. MHD_run is
guaranteed to not block; however, access handlers and response processing
callbacks that it invokes may block. This mode is useful if a
single-threaded implementation is desired and in particular if the main
application already uses a select loop for its processing.*" More ...
<https://www.gnu.org/software/libmicrohttpd/>

Enjoy MHD! ☺
Post by Santos Das
Hi,
Thank you for the quick reply. I have one more question, please help in
clarifying -
Can "libmicrohttpd" run as a part of the application event loop or is it *mandatory
*for the "libmicrohttpd" to have its own event loop?
thanks, santos
Post by Christian Grothoff
Post by Santos Das
Hi,
Can anyone please confirm if libmicrohttpd supports the Async handling?
Yes, it supports asynchronous processing.
Post by Santos Das
Also, any information on the performance of libmicrohttps will be
useful.
Let's just say if used properly, it will never be anywhere near the
bottleneck. We know people running 100,000 requests/s on a single system
with MHD years ago. Quite likely to do more today, but very difficult to
test: when benchmarking, you will always be benchmarking your clients,
your network or your application logic long before hitting any MHD
threshold (on sane operating systems).
--
Silvio Clécio
Santos Das
2018-08-23 19:09:13 UTC
Permalink
Hi,

Thanks a lot. Is there any significant performance impact when it runs in
this mode ?

Has anyone compared its performance against "mongoose " ?

I''m evaluating a http library for my C++ based application microservices
. I am evaluating libraries that can provide our C++ workers with native
HTTP capabilities.


I’m defining native as:

- No additional threads other than those spawned by the application when
it chooses to use blocking calls (entirely optional)
- No additional queueing
- Native sockets interface with full use of listen, accept, bind,
connect, recv, send.


Do you think libmicrohttpd is the best choice or is there any better
alternatives for me ?

Please advise.

thanks, santos
Post by silvioprog
Hello Santos.
"*The fourth threading model (used when no specific flag is given), uses
no threads. Instead, the main application must (periodically) request file
descriptor sets from MHD, perform a select call and then call MHD_run.
MHD_run will then process HTTP requests as usual and return. MHD_run is
guaranteed to not block; however, access handlers and response processing
callbacks that it invokes may block. This mode is useful if a
single-threaded implementation is desired and in particular if the main
application already uses a select loop for its processing.*" More ...
<https://www.gnu.org/software/libmicrohttpd/>
Enjoy MHD! ☺
Post by Santos Das
Hi,
Thank you for the quick reply. I have one more question, please help in
clarifying -
Can "libmicrohttpd" run as a part of the application event loop or is it *mandatory
*for the "libmicrohttpd" to have its own event loop?
thanks, santos
Post by Christian Grothoff
Post by Santos Das
Hi,
Can anyone please confirm if libmicrohttpd supports the Async handling?
Yes, it supports asynchronous processing.
Post by Santos Das
Also, any information on the performance of libmicrohttps will be
useful.
Let's just say if used properly, it will never be anywhere near the
bottleneck. We know people running 100,000 requests/s on a single system
with MHD years ago. Quite likely to do more today, but very difficult to
test: when benchmarking, you will always be benchmarking your clients,
your network or your application logic long before hitting any MHD
threshold (on sane operating systems).
--
Silvio Clécio
silvioprog
2018-08-23 19:48:46 UTC
Permalink
You're welcome. ☺
Post by Santos Das
Hi,
Thanks a lot. Is there any significant performance impact when it runs in
this mode ?
I'm using the built-in MHD main loop through a recent released project
called Sagui Project <https://risoflora.github.io/libsagui/>. Take a look
at some benchmarks vs NodeJS/Nginx
<https://github.com/risoflora/libsagui/tree/master/examples/benchmark> (this
high-performance would not be possible without MHD library, thanks
Christian, Evgeny and all). You should test MHD in a minimal project to
check its features. Feel free to ask questions regarding it.

Has anyone compared its performance against "mongoose " ?
Some time ago: I tested MHD vs Mongoose vs Soup
<https://lists.gnu.org/archive/html/libmicrohttpd/2017-01/msg00022.html>.
I'm inclined to add Mongoose in my new tests
<https://github.com/risoflora/libsagui/tree/master/examples/benchmark>.
Post by Santos Das
I''m evaluating a http library for my C++ based application microservices
. I am evaluating libraries that can provide our C++ workers with native
HTTP capabilities.
- No additional threads other than those spawned by the application
when it chooses to use blocking calls (entirely optional)
- No additional queueing
- Native sockets interface with full use of listen, accept, bind,
connect, recv, send.
Please take a look at MHD reference manual
<https://www.gnu.org/software/libmicrohttpd/manual/libmicrohttpd.html> and this
tutorial <https://www.gnu.org/software/libmicrohttpd/tutorial.html>, it
contains a lot of info and tips regarding the library features. Also, take
a look at daemon.c and connection.c files here
<https://github.com/Karlson2k/libmicrohttpd/tree/master/src/microhttpd>. ☺
Post by Santos Das
Do you think libmicrohttpd is the best choice or is there any better
alternatives for me ?
I'm working a lot to release a new project for Delphi XE (Pascal and C++)
and Free Pascal
<https://github.com/silvioprog/brookframework/tree/tardigrade>, and I have
plan to support Python and Java too. I tested a lot of libraries before
(libsoup, mongoose, libuv based libraries, libevent based libraries and so
on), but MHD was the minimal, simplest, safe and performatic ANSI C
library to develop cross-platform HTTP(S) servers. So, since we are in a
similar scenario, it seems MHD is the best choice for you, please take a
time to test it. 😉
Post by Santos Das
Please advise.
thanks, santos
--
Silvio Clécio
Christian Grothoff
2018-08-23 23:58:10 UTC
Permalink
This post might be inappropriate. Click to display it.
silvioprog
2018-08-24 00:39:38 UTC
Permalink
Hello Christian,

On Thu, Aug 23, 2018 at 8:58 PM Christian Grothoff <***@gnunet.org>
wrote:
[...]
Post by Christian Grothoff
Well, we have a list of alternatives on the MHD web site. But naturally
few people on this list would think they are as useful for _their_
usecases. ;-)
I would like to add my library to the page "Projects that use
libmicrohttpd". How to do that? :-)

Thank you!
--
Silvio Clécio
Santos Das
2018-08-24 14:12:21 UTC
Permalink
Hi,

Thanks for the prompt reply. I have few more questions., kindly see if you
could help.

a. Does this have a transaction scoreboarding capability (e.g., to match up
asynchronous operations)? The use of the passed argument *cls seems to
imply this? That is, when you get an inbound transation you allocate a
tracking object in application space and hand its pointer to libhttpd so
that it can give it back to you later (i.e., you are giving the response
and it asynchronously asks for the next chunk of bytes in the response).

b. Does it support chunk-encoding of responses?

c. Does MHD has inbuilt JSON encode/decode capabilities ?

Thanks, Santos
Post by Christian Grothoff
Post by Santos Das
Hi,
Thanks a lot. Is there any significant performance impact when it runs
in this mode ?
Not inherently, but you don't get the thread-pool feature that way (at
least not without quite a bit of work by you!). My real
high-performance setups use the thread pool (because my application
logic requires some CPU time, not so much for MHD), but of course you
could hack up your own. But just FYI: that's not trivial.
Post by Santos Das
Has anyone compared its performance against "mongoose " ?
I'm not aware of a direct 1:1 comparison, but as I said, it is very hard
to benchmark the HTTP logic itself.
Post by Santos Das
I''m evaluating a http library for my C++ based application
microservices . I am evaluating libraries that can provide our C++
workers with native HTTP capabilities.
* No additional threads other than those spawned by the application
when it chooses to use blocking calls (entirely optional)
* No additional queueing
* Native sockets interface with full use of listen, accept, bind,
connect, recv, send.
Do you think libmicrohttpd is the best choice or is there any better
alternatives for me ?
Well, we have a list of alternatives on the MHD web site. But naturally
few people on this list would think they are as useful for _their_
usecases. ;-)
https://github.com/etr/libhttpserver
But I don't know if it is any good (never tried).
Happy hacking!
Christian
Christian Grothoff
2018-08-24 14:40:56 UTC
Permalink
Post by Santos Das
Hi,
Thanks for the prompt reply. I have few more questions., kindly see if
you could help.
a. Does this have a transaction scoreboarding capability (e.g., to match
up asynchronous operations)?   The use of the passed argument *cls seems
to imply this?   That is, when you get an inbound transation you
allocate a tracking object in application space and hand its pointer to
libhttpd so that it can give it back to you later (i.e., you are giving
the response and it asynchronously asks for the next chunk of bytes in
the response).
I'm not sure I'd call this scoreboarding, but yes, the 'cls' is there so
that the application can associate state with the request for later
continuations.
Post by Santos Das
b. Does it support chunk-encoding of responses?
Yes.
Post by Santos Das
c. Does MHD has inbuilt JSON encode/decode capabilities ?
No, but easy to add by linking against libjanson.

-Christian
Santos Das
2018-08-24 18:05:23 UTC
Permalink
Thank you once again for the prompt reply.

I have few more questions. Are you aware of any project which has
integrated libmicrohttpd along with libcurl without losing any
functionality of MHD ? I really want to run in the single threaded model as
I mentioned above.
I looked at the following . But, was not quite impressive.

https://github.com/babelouest/ulfius

Also, any comment on the following ? I hope again, we are not losing any
functionality of libmicrohttpd here?

https://github.com/maru/libmicrohttpd-http2

Thanks, santos
Post by Christian Grothoff
Post by Santos Das
Hi,
Thanks for the prompt reply. I have few more questions., kindly see if
you could help.
a. Does this have a transaction scoreboarding capability (e.g., to match
up asynchronous operations)? The use of the passed argument *cls seems
to imply this? That is, when you get an inbound transation you
allocate a tracking object in application space and hand its pointer to
libhttpd so that it can give it back to you later (i.e., you are giving
the response and it asynchronously asks for the next chunk of bytes in
the response).
I'm not sure I'd call this scoreboarding, but yes, the 'cls' is there so
that the application can associate state with the request for later
continuations.
Post by Santos Das
b. Does it support chunk-encoding of responses?
Yes.
Post by Santos Das
c. Does MHD has inbuilt JSON encode/decode capabilities ?
No, but easy to add by linking against libjanson.
-Christian
Christian Grothoff
2018-08-24 18:28:59 UTC
Permalink
Post by Santos Das
Thank you once again for the prompt reply.
I have few more questions. Are you aware of any project which has
integrated libmicrohttpd along with libcurl without losing any
functionality of MHD ? I really want to run in the single threaded model
as I mentioned above.
GNUnet and GNU Taler (in Twister) do this for implementing an http
proxy, basically HTTP server via MHD, then libcurl for the HTTP client:

https://git.taler.net/twister.git/

I don't see why you think integrating with libcurl would result in a
loss of functionality.
Santos Das
2018-08-24 18:56:09 UTC
Permalink
Thank you for your reply. My application can be a client as well as a
server as it does the send and receive of the HTTP message.

My main worry was, when people integrate two libraries, they to do some
modifications to take some advantage and then they lose out some core
features. I was worried if that was the case.

Thank you for the pointer. I will take a look at that.


thanks, santos
Post by Christian Grothoff
Post by Santos Das
Thank you once again for the prompt reply.
I have few more questions. Are you aware of any project which has
integrated libmicrohttpd along with libcurl without losing any
functionality of MHD ? I really want to run in the single threaded model
as I mentioned above.
GNUnet and GNU Taler (in Twister) do this for implementing an http
https://git.taler.net/twister.git/
I don't see why you think integrating with libcurl would result in a
loss of functionality.
Santos Das
2018-08-24 19:24:09 UTC
Permalink
Hi,

What is the plan of supporting http2 for MHD?

I saw this project and the comments. Can you please comment ?. The libcurl
supports http2 with 3rd party nghttp2. So, wondering what is the similar
support for MHD ? Is there any recommended project for the same ?

https://github.com/maru/libmicrohttpd-http2

https://lists.gnu.org/archive/html/libmicrohttpd/2016-08/msg00032.html
Post by Christian Grothoff
Post by Santos Das
Thank you once again for the prompt reply.
I have few more questions. Are you aware of any project which has
integrated libmicrohttpd along with libcurl without losing any
functionality of MHD ? I really want to run in the single threaded model
as I mentioned above.
GNUnet and GNU Taler (in Twister) do this for implementing an http
https://git.taler.net/twister.git/
I don't see why you think integrating with libcurl would result in a
loss of functionality.
Christian Grothoff
2018-09-05 09:39:45 UTC
Permalink
This post might be inappropriate. Click to display it.
Kunal Ekawde
2018-09-27 04:34:49 UTC
Permalink
Hi,

I'm using the same thread as its related to it.
Wanted to confirm this behavior.
MHD is running with external epoll using no new threads for MHD with
suspend/resume.
When we receive external http req, we suspend when response is not sent in
same flow, when data is available, connection is resumed. MDH_run is only
invoked in epoll loop. So the actually send will be only when this gets
invoked right ? so in between resume and send the thread is free and
continues. Basically since we have MHD as a layer to app, on send_response
we need to save the data, response code, headers etc. If the thread breaks,
the send_response caller could free the alloc'ed memory or stack rewind, so
which means we need to save this data on heap as when actual send is
invoked from accessHandlerCallback, this data is available.

Thanks,
Kunal
Post by Christian Grothoff
Hi!
There is no official support for HTTP2 at this time, and there is no
timeline for adding support either. The easiest way to get HTTP2
support would be to run your MHD behind a reverse proxy (Apache/nginx)
that supports HTTP2.
Happy hacking!
Christian
Post by Santos Das
Hi,
What is the plan of supporting http2 for MHD?
I saw this project and the comments. Can you please comment ?. The
libcurl supports http2 with 3rd party nghttp2. So, wondering what is the
similar support for MHD ? Is there any recommended project for the same ?
https://github.com/maru/libmicrohttpd-http2
https://lists.gnu.org/archive/html/libmicrohttpd/2016-08/msg00032.html
Post by Santos Das
Thank you once again for the prompt reply.
I have few more questions. Are you aware of any project which has
integrated libmicrohttpd along with libcurl without losing any
functionality of MHD ? I really want to run in the single threaded
model
Post by Santos Das
as I mentioned above.
GNUnet and GNU Taler (in Twister) do this for implementing an http
proxy, basically HTTP server via MHD, then libcurl for the HTTP
https://git.taler.net/twister.git/
I don't see why you think integrating with libcurl would result in a
loss of functionality.
--
~Kunal
Santos Das
2018-08-27 11:35:58 UTC
Permalink
Hi,

Thanks for your reply. I have a question on how we do the asynchronous
operation (when I am running the michrohttpd as a part of my thread and in
the same event loop) ?

For example, my application received a http message and as a part of
handling the message it has to send out another request (for example, I
trigger a message over diameter interface) and will send out the http
response only after receiving the response from my created procedures (for
example in this case the http response would be sent once the reply over
diameter interface is received.

Can the application send and receive the data through the callback ?

Could you please let me know how this can be achieved ?

Thanks, Santos
Post by Christian Grothoff
Post by Santos Das
Thank you once again for the prompt reply.
I have few more questions. Are you aware of any project which has
integrated libmicrohttpd along with libcurl without losing any
functionality of MHD ? I really want to run in the single threaded model
as I mentioned above.
GNUnet and GNU Taler (in Twister) do this for implementing an http
https://git.taler.net/twister.git/
I don't see why you think integrating with libcurl would result in a
loss of functionality.
Santos Das
2018-08-28 18:05:05 UTC
Permalink
Hi,
Any thoughts on this question?

Thanks in advance.
-santos
Post by Santos Das
Hi,
Thanks for your reply. I have a question on how we do the asynchronous
operation (when I am running the michrohttpd as a part of my thread and in
the same event loop) ?
For example, my application received a http message and as a part of
handling the message it has to send out another request (for example, I
trigger a message over diameter interface) and will send out the http
response only after receiving the response from my created procedures (for
example in this case the http response would be sent once the reply over
diameter interface is received.
Can the application send and receive the data through the callback ?
Could you please let me know how this can be achieved ?
Thanks, Santos
Post by Christian Grothoff
Post by Santos Das
Thank you once again for the prompt reply.
I have few more questions. Are you aware of any project which has
integrated libmicrohttpd along with libcurl without losing any
functionality of MHD ? I really want to run in the single threaded model
as I mentioned above.
GNUnet and GNU Taler (in Twister) do this for implementing an http
https://git.taler.net/twister.git/
I don't see why you think integrating with libcurl would result in a
loss of functionality.
Christian Grothoff
2018-08-23 18:44:30 UTC
Permalink
Post by Santos Das
Hi,
Thank you for the quick reply. I have one more question, please help in
clarifying -
Can "libmicrohttpd" run as a part of the application event loop or is it
*_mandatory _*for the  "libmicrohttpd"  to have its own event loop?
It can run as part of the application's event loop.

You can find a simple example here:

https://git.taler.net/exchange.git/tree/src/bank-lib/fakebank.c

The application's event loop here is easily identified as it is the
GNUNET_SCHEDULER*-API.

The code shows integration both with the select() and epoll()-based
versions of MHD.
Loading...