You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* fix RUBY-1388
* Streamline client construction
* try this
* recreate cluster upon reconnection to avoid using old mutexes in monitoring
* Fix tests
* review feedback
* Integration test for reconnecting a client
* Test monitor thread resurrection
Copy file name to clipboardExpand all lines: source/tutorials/ruby-driver-create-client.txt
+59-15Lines changed: 59 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -494,6 +494,22 @@ Details on Timeout Options
494
494
`CRUD specification <https://github.com/mongodb/specifications/blob/master/source/crud/crud.rst>`_ for details on
495
495
operations that support this option.
496
496
497
+
498
+
TCP Keepalive Configuration
499
+
---------------------------
500
+
501
+
The driver sets TCP keepalive by default. The following default values are also set if the system
502
+
value can be determined and if the driver default value is less than the system value.
503
+
504
+
- ``tcp_keepalive_time``: 300 seconds
505
+
- ``tcp_keepalive_intvl``: 10 seconds
506
+
- ``tcp_keepalive_cnt``: 9 probes
507
+
508
+
509
+
Please see the `MongoDB Diagnostics FAQ keepalive section <https://github.com/mongodb/specifications/blob/master/source/server-selection/server-selection.rst#serverselectiontimeoutms>`_
510
+
for instructions on setting these values at the system level.
511
+
512
+
497
513
Details on Connection Pooling
498
514
-----------------------------
499
515
@@ -555,6 +571,49 @@ When ``#close`` is called on a client by any thread, all connections are closed:
555
571
556
572
client.close
557
573
574
+
575
+
Use with Forking Servers
576
+
------------------------
577
+
578
+
When using the Mongo Ruby driver with a forking web server such as Unicorn,
579
+
worker processes should generally each have their own Mongo::Client instances.
580
+
This is because:
581
+
582
+
1. The background threads remain in the parent process and are not transfered
583
+
to the child process.
584
+
2. File descriptors like network sockets are shared between parent and
585
+
child processes.
586
+
587
+
It is easiest to not create any Mongo::Client instances prior to the fork.
588
+
If the parent process needs to perform operations on the MongoDB database,
589
+
reset the client in an ``after_fork`` handler which is defined in
590
+
``unicorn.rb``::
591
+
592
+
.. code-block:: ruby
593
+
594
+
after_fork do |server, worker|
595
+
$client.close
596
+
$client.reconnect
597
+
end
598
+
599
+
The above code assumes your Mongo::Client instance is stored in the $client
600
+
global variable. It also keeps the MongoDB connection in the parent process
601
+
around, and this connection will continue to consume resources such as
602
+
a connection slot. If the parent process performs one time operation(s) on
603
+
MongoDB and does not need its MongoDB connection once workers are forked,
604
+
the following code will close the connection in the parent::
605
+
606
+
.. code-block:: ruby
607
+
608
+
before_fork do |server, worker|
609
+
$client.close
610
+
end
611
+
612
+
after_fork do |server, worker|
613
+
$client.reconnect
614
+
end
615
+
616
+
558
617
Details on Retryable Writes
559
618
---------------------------
560
619
@@ -592,18 +651,3 @@ be automatically retried:
592
651
- ``collection#find_one_and_replace``
593
652
- ``collection#find_one_and_delete``
594
653
- ``collection#bulk_write`` (for all single statement ops, i.e. not for ``update_many`` or ``delete_many``)
595
-
596
-
597
-
TCP Keepalive Configuration
598
-
---------------------------
599
-
600
-
The driver sets TCP keepalive by default. The following default values are also set if the system
601
-
value can be determined and if the driver default value is less than the system value.
602
-
603
-
- ``tcp_keepalive_time``: 300 seconds
604
-
- ``tcp_keepalive_intvl``: 10 seconds
605
-
- ``tcp_keepalive_cnt``: 9 probes
606
-
607
-
608
-
Please see the `MongoDB Diagnostics FAQ keepalive section <https://github.com/mongodb/specifications/blob/master/source/server-selection/server-selection.rst#serverselectiontimeoutms>`_
609
-
for instructions on setting these values at the system level.
0 commit comments