|
The C driver's general approach to Server Discovery And Monitoring is:
A mongoc_client_t that you get from the mongoc_client_pool_t will share one monitor with other clients from the same pool. That monitor runs periodically on a background thread, slowly under normal circumstances, quickly when any client wants to select a server type that's unavailable (e.g., while a client wants to write and the primary is unavailable). The monitor is uses non-blocking sockets to check servers concurrently; the overall effect conforms to SDAM's description of multithreaded and asynchronous clients, even though the C driver uses one thread to accomplish monitoring.
A non-pooled mongoc_client_t has its own monitor which runs on the current thread. It blocks to rescan the topology periodically, or whenever selection fails or the topology description is "stale". It conforms to SDAM's description of a single-threaded client, plus an optimization: during the rescan it fans out to all servers concurrently with non-blocking sockets. So the recheck only takes as long as the slowest server, or the connectTimeoutMS, rather than requiring the sum of all server latencies.
|