Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test m2snooty (TEST) #936

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions source/test/cxx-connection-pools.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

+++
date = "2017-04-18 13:39:39-04:00"
title = "Connection pools"
[menu.main]
weight = 15
parent="mongocxx3"
+++

``mongocxx::client`` vs ``mongocxx::pool``
--------------------------------------------------

A standalone ``mongocxx::client`` uses a single-threaded algorithm to
monitor the state of the cluster it's connected to. When connected to a
replica set, the thread "stops the world" every 60 seconds to check the
status of the cluster. A ``mongocxx::pool``\ , on the other hand, uses a
separate background thread for each server in the cluster, each of which
checks the status of the server it monitors every 10 seconds. Because of
the performance advantages of monitoring the cluster in the background
rather than "stopping the world", it's highly recommended to use a
``mongocxx::pool`` rather than a set of standalone clients if your
application has access to multiple threads, even if your application only
uses one thread.

Connection pools and thread safety
----------------------------------

A ``mongocxx::pool`` can be shared across multiple threads and used to create
clients. However, each ``mongocxx::client`` can only be used in a single
thread. See the `thread safety documentation <../thread-safety/>`__ for
details on how to use a ``mongocxx::client`` in a thread-safe manner.

Configuring a connection pool
-----------------------------

The number of clients in a connection pool is determined by the URI
parameters ``minPoolSize`` and ``maxPoolSize``. The ``minPoolSize`` and
``maxPoolSize`` options set resource usage targets for when the driver is
idle or fully-utilized. When fully utilized, up to maxPoolSize clients
are available. When clients are returned to the pool, they are destroyed
until the pool has shrunk again to the minPoolSize.

.. list-table::
:header-rows: 1

* - ‌‌
* - maxPoolSize
- The maximum number of clients created by a mongocxx::pool (both in the pool and checked out). The default value is 100. Once it is reached, mongocxx::pool::acquire blocks until another thread returns a client to the pool.
* - minPoolSize
- Sets a target size for the pool when idle. Once this many clients have been created, there will never be fewer than this many clients in the pool. If additional clients above minPoolSize are created, they will be destroyed when returned to the pool. The default value is "0", which disables this feature. When disabled, clients are never destroyed.


Using a connection pool
-----------------------

To use a connection pool, first create a ``mongocxx::pool``\ , passing the URI
as an argument. Then, call ``mongocxx::pool::acquire`` to receive a client
from the pool. The client will automatically be returned to the pool when
it goes out of scope.

See the `connection pool example <https://github.com/mongodb/mongo-cxx-driver/blob/master/examples/mongocxx/pool.cpp>`__
for more details.
173 changes: 173 additions & 0 deletions source/test/cxx-installation-index.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@

+++
date = "2020-09-26T13:14:52-04:00"
title = "Installing the mongocxx driver"
[menu.main]
identifier = "mongocxx3-installation"
parent = "mongocxx3"
weight = 8
+++

Prerequisites
-------------


* Any standard Unix platform, or Windows 7 SP1+
* A compiler that supports C++11 (gcc, clang, or Visual Studio)
* `CMake <https://cmake.org>`__ 3.2 or later
* `boost <https://www.boost.org>`__ headers (optional)

If you encounter build failures or other problems with a platform configuration
that meets the above prerequisites, please file a bug report via
`JIRA <https://jira.mongodb.com/browse/CXX/>`__.

Installation
------------

To configure and install the driver, follow the instructions for your platform:


* `Configuring and installing on Windows <{{< ref "/mongocxx-v3/installation/windows" >}}>`__
* `Configuring and installing on macOS <{{< ref "/mongocxx-v3/installation/macos" >}}>`__
* `Configuring and installing on Linux <{{< ref "/mongocxx-v3/installation/linux" >}}>`__

Advanced Options
----------------


* `Advanced Configuration and Installation Options <{{< ref "/mongocxx-v3/installation/advanced" >}}>`__

Package Managers
----------------

The Mongo C++ driver is available in the following package managers.


* `Vcpkg <https://vcpkg.io/>`__ (search for mongo-cxx-driver)
* `Conan <https://conan.io/center/recipes/mongo-cxx-driver>`__
* `Homebrew <https://formulae.brew.sh/formula/mongo-cxx-driver>`__

Vcpkg Install Instructions
~~~~~~~~~~~~~~~~~~~~~~~~~~

If you do not already have Vcpkg installed, install it with the following
command:

.. code-block::

$ git clone https://github.com/Microsoft/vcpkg.git
$ cd vcpkg
$ ./bootstrap-vcpkg.sh

Optionally, to install with Visual Studio integration:

.. code-block::

vcpkg integrate install

Install the driver. (You may need to ``git pull`` to get the latest version of the
driver)

.. code-block::

$ ./vcpkg install mongo-cxx-driver

You can use the toolchain file, ``vcpkg.cmake``\ , to instruct CMake where to find
the development files, for example:

.. code-block::

-DCMAKE_TOOLCHAIN_FILE=/<path to vcpkg repo>/vcpkg/scripts/buildsystems/vcpkg.cmake

You can find the header files in:

.. code-block::

vcpkg/installed/<CPU ARCHITECTURE>-<OPERATING SYSTEM>/include/

The library files are in:

.. code-block::

vcpkg/installed/<CPU ARCHITECTURE>-<OPERATING SYSTEM>/lib/

Conan Install Instructions
~~~~~~~~~~~~~~~~~~~~~~~~~~

Package Specifier: ``mongo-cxx-driver/3.8.0``

If you do not already have Conan installed, then install it and run the Conan
initalization command below:

.. code-block::

$ pip install conan
$ conan profile detect --force

Add the following to your ``conanfile.txt``

.. code-block::

[requires]
mongo-cxx-driver/3.8.0
[generators]
CMakeDeps
CMakeToolchain

Install the driver via Conan, and build your project:

.. code-block::

$ conan install conanfile.txt --output-folder=build --build=missing
$ cmake \
-B build \
-DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake \
-DCMAKE_BUILD_TYPE=Release
$ cmake --build build

Homebrew
~~~~~~~~

For MacOS users, homebrew is a convienent way to install the C++ driver.

.. code-block::

brew install mongo-cxx-driver

For an Apple Silicon Mac
````````````````````````

Headers can be found in:

.. code-block::

/opt/homebrew/include/mongocxx/v_noabi/
/opt/homebrew/include/bsoncxx/v_noabi/

Library files can be found in:

.. code-block::

/opt/homebrew/lib/

For an Intel Mac
````````````````

Headers can be found in:

.. code-block::

/usr/local/include/mongocxx/v_noabi/
/usr/local/include/bsoncxx/v_noabi/

Library files can be found in:

.. code-block::

/usr/local/lib/

Docker Image
------------

You can find a pre-built docker image for the C++ driver in
`Docker Hub <https://hub.docker.com/r/mongodb/mongo-cxx-driver>`__.
Loading
Loading