Mongoose is single-threaded, non-blocking, async.
There are many products that use the same model.
For example, redis <http://redis.io/>, or node.js <http://nodejs.org/>. If
you tell their developers their software is not able to handle concurrent
requests, they could be surprised.

I believe you have a wrong idea about how mongoose works. If you think that
mongoose accepts the connection, then reads the request, then calls the
callback to send the reply and could not process other requests during that
--- that's wrong understanding.

Mongoose can accept multiple connections, and read request from many of
them simultaneously. When the request is fully buffered, callback is
called. Callback must not block, otherwise it can stall the serving.

Blocking or otherwise long-running operations must be moved to dedicated
threads. A callback that needs to get a result of long-running operation
should schedule it, return MG_MORE -- and not block mongoose. Mongoose will
send MG_POLLs to that connection, where callback may decide to complete the
reply, or, alternatively, other thread could mg_wakeup_server_ex() to push
the result of the long-running operation to the respective connection.

If there are many cores, mongoose instances could be created per core,
sharing the same listening socket -- that would do load balancing.

My benchmarks shows that old, multithreaded mongoose is noticeably slower
then singly-threaded mongoose, running on my 8-core development box running
simple "hello world" example. Benchmarks were done using well known
benchmarking tools like ab, wrk, siege - with different concurrency levels,
from 1 to hundreds.

I hope that clears up the architecture and how concurrent requests are
processed.



On Thu, Aug 7, 2014 at 5:33 PM, Scott Ellis <[email protected]> wrote:

> OK thanks. To be clear then, with the previous multi-threaded version,
> mongoose itself handled multiple concurrent requests by starting new
> threads internally, but now with the single threaded mongoose, it only
> handles one request at  time in serial, so it is up to the user callback
> functions to start new threads to support multiple concurrent requests?
>
>
> On Thursday, August 7, 2014 9:52:25 AM UTC-6, Sergey Lyubka wrote:
>
>> On Thu, Aug 7, 2014 at 4:51 PM, Scott Ellis <[email protected]> wrote:
>>
>>> Ok but if a user callback takes a while to complete, it appears that
>>> mongoose will not serve the next request until the previous user callback
>>> completes. Is that correct?
>>
>>
>> That is correct.
>>
>  --
> 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 [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/mongoose-users.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/mongoose-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to