Mongoose multithread restfull server

462 views
Skip to first unread message

phpprogrammer

unread,
Nov 3, 2015, 7:45:41 PM11/3/15
to mongoose-users
Hi,

I have an API service that using long polling/commet tehnique.
I'm using apache-prefork+mod-php, that's just work. But I'm just realized, my solution resulted 15-20 mb of ram, per connection. Which is bad.
I can use apache-mpm-worker as alternative, but I will look into another alternative in the first.

Now, I'm just realized, that mongoose is capable to act as long polling server, using multithread server (using pthread).
1. I have read that pthread library, need 5mb of ram per new thread. This is caused by glibc library that's bloated. But I'm just read it from googling. Is that right?
2. Can I use uclibc or musl-libc, compiled with monggose, to get tiny memory footprint per thread?
3. How I can set pthread stack size in monggose? 

Thanks.

Sergey Lyubka

unread,
Nov 5, 2015, 4:13:22 AM11/5/15
to mongoose-users
Thanks for the background.

Note that thread are to be used in two situations:
  1.  Request handler needs to do some long computation or blocking call (e.g. read from a slow database) to serve the request. In that case, to avoid blocking other connections, request handler must be run in a separate thread
  2.  A very high performance (e.g. millions of requests / second) is required. Then, on multicore machine, each core can be given a copy of a listening socket and it's own mongoose context.

Could you elaborate why exactly do you need multithreading, please?
Mongoose can do long polling with a single thread.



--
You received this message because you are subscribed to the Google Groups "mongoose-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-user...@googlegroups.com.
To post to this group, send email to mongoos...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongoose-users.
For more options, visit https://groups.google.com/d/optout.

phpprogrammer

unread,
Nov 5, 2015, 6:48:27 AM11/5/15
to mongoose-users
> Could you elaborate why exactly do you need multithreading, please?
> Mongoose can do long polling with a single thread.

You can imagine my use case as a chat server. 
A browser widget, act as a chat widget, which will display as soon as possible after receiving reply.
On the chat server, I maintain a database, that logs "who reply to whom" records.

When a chat widget request chat reply from chat server, it request it with using long timeout.
On the server side app, app hold this session, and periodically query "who reply to whom" database, to find if the chat session already replied.
If the app server find the record needed, then it will be replied to the chat widget immediately.

From my use case above, it ca be understand, that many chat session can happened at the same time.
So if I use single thread server (or thread pool), when app server do query "who reply to whom" database periodically, it will block another chat server.
To avoid this block, I must use multithread/multifork web server, that handle one session using one thread.

Should I use multithread server configuration in monggose?

Sergey Lyubka

unread,
Nov 5, 2015, 7:40:11 AM11/5/15
to mongoose-users
If the database query is fast, there is no need to use multiple threads.

Reply all
Reply to author
Forward
0 new messages