beam-telemetry / telemetry_metrics_statsd

Telemetry.Metrics reporter for StatsD-compatible metric servers
https://hexdocs.pm/telemetry_metrics_statsd
MIT License
75 stars 44 forks source link

Allow sending to IPs and default to 127.0.0.1 #23

Closed hkrutzer closed 4 years ago

hkrutzer commented 4 years ago

I am using TelemetryMetricsStatsd to send Ecto query telemetry. I noticed this slowed down some of our calls. One of the more expensive operations is apparently :inet_udp.getaddr/1. However, there is no need to look up localhost using this function. I have included some benchmark information collected with fprof below.

When using localhost:

TelemetryMetricsStatsd.UDP.send/2                                   12      12.319       0.088
  :gen_udp.send/4                                                   12      12.319       0.088  <--
    :inet_db.lookup_socket/1                                        12       0.051       0.034
    :inet_udp.send/4                                                12       0.622       0.023
    :inet_udp.getaddr/1                                             12      11.545       0.020
    :inet_udp.getserv/1                                             12       0.013       0.013

When using 127.0.0.1:

TelemetryMetricsStatsd.UDP.send/2                                   12       2.560       0.095
  :gen_udp.send/4                                                   12       2.560       0.095  <--
    :inet_db.lookup_socket/1                                        12       0.061       0.040
    :inet_udp.send/4                                                12       2.181       0.024
    :inet_udp.getaddr/1                                             12       0.208       0.018
    :inet_udp.getserv/1                                             12       0.015       0.015

Load tests of my application also show a significant performance improvement after this change.

arkgil commented 4 years ago

@hkrutzer the formatting is off now, could you run mix format and push that?

hkrutzer commented 4 years ago

Oops, sorry

arkgil commented 4 years ago

Thanks! ⚡️