Browse Source

Moved strategy settings to it's proper place and added better comment.

Raoul Hess 10 years ago
parent
commit
b787527b7a
1 changed files with 10 additions and 7 deletions
  1. 10 7
      src/mysql_poolboy.erl

+ 10 - 7
src/mysql_poolboy.erl

@@ -31,11 +31,7 @@
 %% @doc Adds a pool to the started mysql_poolboy application.
 add_pool(PoolName, PoolArgs, MysqlArgs) ->
     %% We want strategy fifo as default instead of lifo.
-    PoolArgs1 = case proplists:is_defined(strategy, PoolArgs) of
-        true  -> PoolArgs;
-        false -> PoolArgs ++ [{strategy, fifo}]
-    end,
-    PoolSpec = child_spec(PoolName, PoolArgs1, MysqlArgs),
+    PoolSpec = child_spec(PoolName, PoolArgs, MysqlArgs),
     supervisor:start_child(mysql_poolboy_sup, PoolSpec).
 
 %% @doc Returns a mysql connection to the given pool.
@@ -49,8 +45,15 @@ checkout(PoolName) ->
 %% @doc Creates a supvervisor:child_spec. When the need to
 %% supervise the pools in another way.
 child_spec(PoolName, PoolArgs, MysqlArgs) ->
-    PoolArgs1 =
-        [{name, {local, PoolName}}, {worker_module, mysql}] ++ PoolArgs,
+    PoolArgs1 = case proplists:is_defined(strategy, PoolArgs) of
+        true  ->
+            [{name, {local, PoolName}}, {worker_module, mysql} | PoolArgs];
+        false ->
+            %% Use fifo by default. MySQL closes unused connections after a certain time.
+            %% Fifo causes all connections to be regularily used which prevents them from
+            %% being closed.,
+            [{strategy, fifo}, {name, {local, PoolName}}, {worker_module, mysql} | PoolArgs]
+    end,
     poolboy:child_spec(PoolName, PoolArgs1, MysqlArgs).
 
 %% @doc Execute a mysql prepared statement with given params.