riemann-java-client icon indicating copy to clipboard operation
riemann-java-client copied to clipboard

Question: getLocalHost each event?

Open lassic opened this issue 10 years ago • 3 comments

Hi,

I noticed that every time a EventDSL is constructed there is a call to getLocalHost, which on my AWS instance has an avg. of 10-20ms per call. It's not much per call perhaps, but accumulates when firing a lot of events.

Do you expect the machine's IP to change during the lifetime of the client? Shouldn't this at least be configurable? It seems like a waste calling this for each event if the IP doesn't change.

I can either submit a PR where I'm statically caching this once and reusing it in the constructor, or if you think this is how it should continue to work I can create a fork.

Thanks!

lassic avatar Dec 21 '14 13:12 lassic

Ah, the joys of the JVM, where getLocalHost makes a call to the DNS resolver, which, on EC2, means a bloody network call.

So we work around this in Riemann proper by a.) reading env-vars depending on platform, b.) shelling out to hostname(1), and c.) caching the result for a minute. https://github.com/aphyr/riemann/blob/master/src/riemann/common.clj#L35-L61. That's probably the right approach to port to the JVM client as well.

aphyr avatar Dec 21 '14 19:12 aphyr

Cool, sorry for the long delay in response. When I get a chance I'll try the same approach and submit a PR.

lassic avatar Dec 31 '14 12:12 lassic

Working on it now.

lassic avatar Jan 01 '15 10:01 lassic