Skip to content

Commit 5d8fc0c

Browse files
committed
limit pool for monitor instance to one
1 parent 3259dc5 commit 5d8fc0c

File tree

3 files changed

+8
-19
lines changed

3 files changed

+8
-19
lines changed

README.md

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,25 @@ to implement the current requirements for the driver.
5959

6060
### Installation:
6161

62-
Add mongodb to your mix.exs `deps` and `:applications` (replace `>= 0.0.0` in `deps` if you want a specific version). Mongodb supports the same pooling libraries db_connection does (currently: no pooling, poolboy, and sbroker). If you want to use poolboy as pooling library you should set up your project like this:
62+
Add mongodb_driver to your mix.exs `deps` and `:applications` (replace `>= 0.0.0` in `deps` if you want a specific version).
63+
The driver supports pooling by db_connection (2.x). If you want to use pooling you should set up your project like this:
6364

6465
```elixir
6566
def application do
66-
[applications: [:mongodb, :poolboy]]
67+
[applications: [:mongodb_driver]]
6768
end
6869

6970
defp deps do
70-
[{:mongodb, ">= 0.0.0"},
71-
{:poolboy, ">= 0.0.0"}]
71+
[{:mongodb_driver, "~> 0.5.0"}]
7272
end
7373
```
7474

7575
Then run `mix deps.get` to fetch dependencies.
7676

7777
### Connection pooling
7878

79-
By default mongodb will start a single connection, but it also supports pooling with the `:pool` option. For poolboy add the `pool: DBConnection.Poolboy` option to `Mongo.start_link` and to all function calls in `Mongo` using the pool.
79+
By default mongodb will start a single connection, but it also supports pooling with the `:pool_size` option.
80+
For 3 connections add the `pool_size: 3` option to `Mongo.start_link` and to all function calls in `Mongo` using the pool.
8081

8182
```elixir
8283
# Starts an unpooled connection
@@ -97,26 +98,14 @@ def start(_type, _args) do
9798
import Supervisor.Spec
9899

99100
children = [
100-
worker(Mongo, [[name: :mongo, database: "test", pool: DBConnection.Poolboy]])
101+
worker(Mongo, [[name: :mongo, database: "test", pool_size: 3]])
101102
]
102103

103104
opts = [strategy: :one_for_one, name: MyApp.Supervisor]
104105
Supervisor.start_link(children, opts)
105106
end
106107
```
107108

108-
DBConnection.Poolboy defaults to [10 Poolboy connections](https://hexdocs.pm/db_connection/1.1.3/DBConnection.Poolboy.html#content), but you can change that with the `:pool_size` option:
109-
```elixir
110-
{:ok, conn} = Mongo.start_link(name: :mongo, database: "test", pool: DBConnection.Poolboy, pool_size: 2)
111-
```
112-
113-
114-
Remember to specify the pool in each query. There is [some discussion](https://github.com/ankhers/mongodb/issues/175) on how to change this requirement.
115-
116-
```elixir
117-
Mongo.find(:mongo, "collection", %{}, limit: 20, pool: DBConnection.Poolboy)
118-
```
119-
120109
### Replica Sets
121110

122111
To connect to a Mongo cluster that is using replica sets, it is recommended to use the `:seeds` list instead of a `:hostname` and `:port` pair.

lib/mongo/mongo_db_connection.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ defmodule Mongo.MongoDBConnection do
157157
with {:ok, %{wire_version: ^wire_version}} <- wire_version(state), do: {:ok, state}
158158
end
159159

160-
161160
def handle_execute_close(query, params, opts, s) do
162161
handle_execute(query, params, opts, s)
163162
end

lib/mongo/monitor.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ defmodule Mongo.Monitor do
4343
|> Keyword.put(:connection_type, :monitor)
4444
|> Keyword.put(:topology_pid, topology_pid)
4545
|> Keyword.put(:pool_size, 1)
46+
|> Keyword.put(:idle_interval, 5_000)
4647

4748
{:ok, pid} = DBConnection.start_link(Mongo.MongoDBConnection, opts)
4849
:ok = GenServer.cast(self(), :check)

0 commit comments

Comments
 (0)