# Apm java agent server\_urls list not balancing

**URL:** <https://discuss.elastic.co/t/apm-java-agent-server-urls-list-not-balancing/177301>\
**Category:** APM\
**Created:** [April 17, 2019, 1:34pm UTC](https://discuss.elastic.co/t/apm-java-agent-server-urls-list-not-balancing/177301 "2019-04-17T13:34:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![moixcruz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/moixcruz/32/40464_2.png) [@moixcruz](https://discuss.elastic.co/u/moixcruz)\
**Post date:** [April 17, 2019, 1:34pm UTC](https://discuss.elastic.co/t/apm-java-agent-server-urls-list-not-balancing/177301/1 "2019-04-17T13:34:05Z")

</div>

Hi! I'm running APM stack all components 6.6.0, and already thinking on upgrade to recently released 7.0.0!

I have mainly java agents (1.6.0) connected to several apm-servers, 3 in test environment.

My java agent is instrumented with properties file:  
service\_name=my-testing-service  
application\_packages=hello-world  
server\_urls=http://apm-server-1.test:8200,[http://apm-server-2.test:8200](http://apm-server-2.test:8200),[http://apm-server-3.test:8200](http://apm-server-3.test:8200)

and in some cases I override the servers url via command line -Delastic.apm.server\_urls=...

While testing it, I see that agent connects only to first available apm server in the list, apm-server-1.test, and doesn't perform any kind of traffic balance

Looking into documentation [https://www.elastic.co/guide/en/apm/agent/java/current/config-reporter.html#config-server-urls](https://www.elastic.co/guide/en/apm/agent/java/current/config-reporter.html#config-server-urls) I cannot find any reference to how it is supposed to work, but I was expecting to distribute the traffic across all available servers.

Can anyone explain exactly how it is supposed to work? should I put a reverse proxy on top of all apm-servers to do it?

Many thanks!

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [April 17, 2019, 1:54pm UTC](https://discuss.elastic.co/t/apm-java-agent-server-urls-list-not-balancing/177301/2 "2019-04-17T13:54:58Z")

</div>

Hi and welcome to the forum 🎉

In order to leverage persistent TCP connections, the Java agent picks a random server url and sticks with it unless this server is under high load or returns a server error. See also [https://github.com/felixbarny/apm-agent-java/blob/c9149dbf340c22cd27617f7c55cee7d8b41999db/apm-agent-core/src/main/java/co/elastic/apm/agent/report/IntakeV2ReportingEventHandler.java#L350](https://github.com/felixbarny/apm-agent-java/blob/c9149dbf340c22cd27617f7c55cee7d8b41999db/apm-agent-core/src/main/java/co/elastic/apm/agent/report/IntakeV2ReportingEventHandler.java#L350)

Note that the connection test on startup only tests the connection to the first APM Server in the list.

Best,  
Felix

---

<div class="post-metadata">

**Author:** ![moixcruz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/moixcruz/32/40464_2.png) [@moixcruz](https://discuss.elastic.co/u/moixcruz)\
**Post date:** [April 17, 2019, 3:46pm UTC](https://discuss.elastic.co/t/apm-java-agent-server-urls-list-not-balancing/177301/3 "2019-04-17T15:46:34Z")

</div>

yeah, has sense, many thanks!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 8, 2019, 11:46am UTC](https://discuss.elastic.co/t/apm-java-agent-server-urls-list-not-balancing/177301/4 "2019-05-08T11:46:40Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
