From 94e553fee6d1aba69c01151608aa6e3db273b67c Mon Sep 17 00:00:00 2001 From: Aaron Alfson Date: Fri, 11 Oct 2024 12:20:25 -0400 Subject: [PATCH 1/3] connection pool documentation --- README.md | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/README.md b/README.md index ffacd4c..0e03716 100644 --- a/README.md +++ b/README.md @@ -158,3 +158,54 @@ Shopify.GraphQL.send("{ shop { name } }", access_token: "...", retry: Shopify.Gr The example above would retry a failed request after 250 milliseconds. By default `Shopify.GraphQL.Retry.Linear` will retry a request immediately if `:retry_in` has no value + +## Connection Pooling + +The out-of-the-box HTTP client, `Shopify.GraphQL.Client.Hackney`, uses hackney's `:default` +connection pool. This pool has a maxiumum of `50` connections. You can tell +`shopify_graphql` to use a different connection pool by specifying the pool name +under http_client_opts in the config. + +**Example** + +Start a new hackney pool in `application.ex` on application startup: + +``` +defmodule BigPool.Application do + use Application + + def start(_type, _args) do + children = [ + ... + :hackney_pool.child_spec(:my_big_pool, timeout: 60_000, recv_timeout: 60_000, max_connections: 1000) + ... + ] + + opts = [strategy: :one_for_one, name: BigPool.Supervisor] + _result = Supervisor.start_link(children, opts) + end +end +``` + +And then specify the new pool name in the request config: + +``` +config = [ + ... + http_client_opts: [pool: :my_big_pool] + ... +] + +query = + """ + { + shop { + name + } + } + """ + +Shopify.GraphQL.send(query, config) + +``` + From 3a3c06e91503b9485700ace07c2ed265553eddd6 Mon Sep 17 00:00:00 2001 From: Aaron Alfson Date: Fri, 11 Oct 2024 12:23:07 -0400 Subject: [PATCH 2/3] updated documentation --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0e03716..6fc179e 100644 --- a/README.md +++ b/README.md @@ -177,7 +177,7 @@ defmodule BigPool.Application do def start(_type, _args) do children = [ ... - :hackney_pool.child_spec(:my_big_pool, timeout: 60_000, recv_timeout: 60_000, max_connections: 1000) + :hackney_pool.child_spec(:my_big_pool, max_connections: 1000) ... ] From ba6cbdf86ab4a710335697857cad0be9ad17be63 Mon Sep 17 00:00:00 2001 From: Aaron Alfson Date: Fri, 11 Oct 2024 12:23:32 -0400 Subject: [PATCH 3/3] updated documentation --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6fc179e..246c41f 100644 --- a/README.md +++ b/README.md @@ -170,7 +170,7 @@ under http_client_opts in the config. Start a new hackney pool in `application.ex` on application startup: -``` +```elixir defmodule BigPool.Application do use Application @@ -189,7 +189,7 @@ end And then specify the new pool name in the request config: -``` +```elixir config = [ ... http_client_opts: [pool: :my_big_pool]