Re: [clojure-mongodb] Monger internals, sync model ?

18 views
Skip to first unread message

Michael Klishin

unread,
Apr 27, 2013, 4:31:20 PM4/27/13
to Monger, a Clojure MongoDB driver

2013/4/28 Yakovlev Roman <feli...@gmail.com>
What happened in monger ? for example 
(monger/find "documents" {:first_name "Ringo"}) is this request sync ? so it waits for response and returns data some time later ?
 Execution is hanging waiting for the data ?

Monger and MongoDB Java driver often return a form of a future (DBCursor or a lazy Clojure sequence).
DBCursor then loads results as needed: if you have 1000 documents in the response but only ever use 20,
it will only load one batch (the size of the batch can be set per connection).

In addition, MongoDB Java driver uses a pool of threads that execute actual requests. AFAIR
its size is in medium hundreds by default. The size can be bumped up but it's only effective
to maybe 2-3K on a 4-8 core machine.

In general, the idea that functions that return values are "blocking" only applies to
environments where you don't have threads (or similar, e.g. Erlang processes), such as Nodejs. On the JVM
plenty of libraries return values that are computed in other threads. So you get both
concurrent (and, depending on the hardware, parallel) execution and a program flow
control you can reason about.

In any case, I hardly believe the client will ever be the bottleneck in any realistic application.
Reply all
Reply to author
Forward
0 new messages