Timeout while fetching cluster config
nitinstp23 opened this issue · 2 comments
exit: ** (exit) exited in: GenServer.call(MyApp.ElasticsearchCluster, :config, 5000)
** (EXIT) time out
File "lib/gen_server.ex", line 836, in GenServer.call/3
File "lib/elasticsearch.ex", line 307, in Elasticsearch.post/4
We get this error randomly in our app while making GET
/POST
requests to Elasticsearch.
Elasticsearch.post/4
calls Elasticsearch .Cluster.Config.get(cluster)
here
And the cluster config is found via this - https://github.com/danielberkompas/elasticsearch-elixir/blob/master/lib/elasticsearch/cluster/cluster.ex#L172
Given the cluster is a GenServer and this call GenServer.call/3
can timeout since a single process can get overloaded under heavy load.
Can we move the :api
out of the cluster config and the user can pass the Elasticsearch.API
behaviour module to functions like Elasticsearch.get
, Elasticsearch.post
, etc?
@danielberkompas Let me know your thoughts.
It does seem like cutting out the GenServer.call
would be beneficial here. My encryption library Cloak handles this by saving the config to an ETS table and then reading it out of the ETS table in a function, rather than via GenServer. Perhaps this could serve as a pattern to fix the issue?
https://github.com/danielberkompas/cloak/blob/master/lib/cloak/vault.ex#L274-L292
@danielberkompas Yes, saving the config in an ETS table will definitely help here. I'll try to send a PR soon!