lexmag / statix

Fast and reliable Elixir client for StatsD-compatible servers
https://hexdocs.pm/statix
ISC License
275 stars 82 forks source link

Ability to open multiple ports to the Statsd UDP port #48

Closed sneako closed 4 years ago

sneako commented 4 years ago

First off, thanks for this great library! It is one of a few libraries that I usually include in a new Elixir application by default.

In one of my higher throughput applications, we started noticing a high number of :busy_port notifications, which turned out to be coming from the Statix port.

I tried out #35 to see if perhaps we could reduce the number of notifications by connecting to the unix socket directly, and also tried #42, switching the Port.command/2 to :gen_udp.send/4, but I am still seeing many busy port notifications.

So I tried another strategy which I have used in this application to reduce pressure, which is to start multiple processes, and choose one randomly.

In my testing I was able to completely eliminate all :busy_port notifications using this strategy.

I am very interested to hear your thoughts on the matter and whether a PR would be accepted.

Here is my fork https://github.com/lexmag/statix/compare/master...sneako:rand-pool.

Thanks again!

lexmag commented 4 years ago

Hi @sneako, I think your strategy is definitely reasonable and if it solves your problem we should get it merged. 👍 I've just added an outer struct (647047286fe3e02ce7bfe9503d15cf85e0da73f4) that should help keeping Conn struct cleaner. Can you please base your implementation on that?