Akka http load balancer

494 views
Skip to first unread message

zergood

unread,
May 27, 2015, 7:21:28 AM5/27/15
to akka...@googlegroups.com
Hello! 

I have a task to develop a http balance loader for my 2 servers. Here is my qucik and very dirty implementation https://gist.github.com/zergood/e705cd6ce4cfec47c0a5. The main problem with it is performance, this solution is slower than my single server. 
What is the reason of performance degradation? Could you give me any advices how to make http load balancer with akka-http? I am using scala-2.11 and akka-http 1.0-RC3.  

Endre Varga

unread,
May 27, 2015, 8:01:34 AM5/27/15
to akka...@googlegroups.com
Hi,

Instead of Http.request, you should use the Flow returned by Http.superPool() (see http://doc.akka.io/docs/akka-stream-and-http-experimental/1.0-RC3/scala/http/client-side/request-level.html). That flattens out the Futures and you get responses instead. That also makes Balance actually aware of response times.

OTOH I don't think performance wise akka-http is currently up to the task of being a balancer. 

-Endre

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Viktor Klang

unread,
May 27, 2015, 8:34:15 AM5/27/15
to Akka User List
On Wed, May 27, 2015 at 2:01 PM, Endre Varga <endre...@typesafe.com> wrote:
Hi,

Instead of Http.request, you should use the Flow returned by Http.superPool() (see http://doc.akka.io/docs/akka-stream-and-http-experimental/1.0-RC3/scala/http/client-side/request-level.html). That flattens out the Futures and you get responses instead. That also makes Balance actually aware of response times.

OTOH I don't think performance wise akka-http is currently up to the task of being a balancer. 

…at the moment.



--
Cheers,

Viktor Klang

unread,
May 27, 2015, 8:34:42 AM5/27/15
to Akka User List
On Wed, May 27, 2015 at 2:33 PM, Viktor Klang <viktor...@gmail.com> wrote:


On Wed, May 27, 2015 at 2:01 PM, Endre Varga <endre...@typesafe.com> wrote:
Hi,

Instead of Http.request, you should use the Flow returned by Http.superPool() (see http://doc.akka.io/docs/akka-stream-and-http-experimental/1.0-RC3/scala/http/client-side/request-level.html). That flattens out the Futures and you get responses instead. That also makes Balance actually aware of response times.

OTOH I don't think performance wise akka-http is currently up to the task of being a balancer. 

…at the moment.

Doh, that "currently" eluded me, see my response as emphasis :)



--
Cheers,

Adam Shannon

unread,
May 27, 2015, 10:14:13 AM5/27/15
to Akka User
Is there a specific reason to not use another piece of software for this? I'm thinking of something like nginx or haproxy. Both of which are much more hardened and performant in regards to serving as proxies for HTTP traffic. 
Adam Shannon | Software Engineer | Banno | Jack Henry
206 6th Ave Suite 1020 | Des Moines, IA 50309 | Cell: 515.867.8337

Илья Ненахов

unread,
May 27, 2015, 2:46:00 PM5/27/15
to akka...@googlegroups.com
I added Http().superPool() to my implementation, but performance is still low. Performance does not increase after adding third server. It seems strange to me. 
Adam, yeah we have a reason not to use nginx or something similar, because there will be an additional business logic, not only load balancing. But if we can't fix the performance issue, nginx and etc would be a "plan b".      

You received this message because you are subscribed to a topic in the Google Groups "Akka User List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/akka-user/_wd1vl0mzfE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to akka-user+...@googlegroups.com.

zergood

unread,
May 28, 2015, 2:09:27 AM5/28/15
to akka...@googlegroups.com
Mistake in docs http://doc.akka.io/docs/akka-stream-and-http-experimental/1.0-RC3/scala/http/client-side/request-level.html. Http.superPool(...) need to be Http().superPool(...) and the same for Http.singleRequest.
 
среда, 27 мая 2015 г., 15:01:34 UTC+3 пользователь drewhk написал:

André

unread,
May 28, 2015, 3:22:35 AM5/28/15
to akka...@googlegroups.com
Source (and edit button) are here. ;)

André

unread,
May 28, 2015, 3:43:28 AM5/28/15
to akka...@googlegroups.com
A quick search revealed some more places that needed fixing. PR submitted.

Endre Varga

unread,
May 28, 2015, 6:09:32 AM5/28/15
to akka...@googlegroups.com
Can you bundle up a very simple self-contained app that just fires up a couple of server systems locally (can be on the same JVM), and uses the balancing logic above? Then we can look into that and see what is going on. 

-Endre

Илья Ненахов

unread,
May 28, 2015, 9:09:03 AM5/28/15
to akka...@googlegroups.com
Here it is https://github.com/zergood/akka-http-loadbalancer.git
Actualy this implemetation is not good, because I've relized that with Http().superFlow I miss request-response ordering. Some requests get wrong responses, it is not so important for this implementation, because all responses are the same.
How can I repair request-response ordering? I think about mapping request to some id, and store all unhandled requests before I get (response, id) from server, another variant is passing RequestContext to superFlow. Are there another ways how to do this?    

P.S in this implementation balancer performance ~900r/s. Single local http server performance is ~4800r/s. 

Endre Varga

unread,
May 28, 2015, 9:54:09 AM5/28/15
to akka...@googlegroups.com
On Thu, May 28, 2015 at 3:08 PM, Илья Ненахов <zergoo...@gmail.com> wrote:
Here it is https://github.com/zergood/akka-http-loadbalancer.git
Actualy this implemetation is not good, because I've relized that with Http().superFlow I miss request-response ordering.

This is why you can attach context to the requests and that will be returned with the response.
 
Some requests get wrong responses, it is not so important for this implementation, because all responses are the same.
How can I repair request-response ordering? I think about mapping request to some id, and store all unhandled requests before I get (response, id) from server, another variant is passing RequestContext to superFlow. Are there another ways how to do this?    

P.S in this implementation balancer performance ~900r/s. Single local http server performance is ~4800r/s. 

I just realized that because you are using the common pool (Http.request is using the same one, too), balancing will have no real effect since all the requests are routed to the same pool anyway. What you need is host level connection pools on each balance edge, pinned to the server you target on that graph edge. 

-Endre

Илья Ненахов

unread,
May 28, 2015, 10:05:44 AM5/28/15
to akka...@googlegroups.com
I did different pool for every server but there was no effect on performance.   

Endre Varga

unread,
May 28, 2015, 10:11:45 AM5/28/15
to akka...@googlegroups.com
But in the code you are using superPool. That gives back the same pool every time, no matter how many times you are using it. Did you try Http.cachedHostConnectionPool(...) explicitly?

-Endre

Илья Ненахов

unread,
May 29, 2015, 4:49:02 AM5/29/15
to akka...@googlegroups.com
I've made new version with cachedPool and one pool for one server https://github.com/zergood/akka-http-loadbalancer.git. There is still no effect on perfomance.
I'd played a little with http config settings and noticed that sometimes when I set pipelining-limit equals two it doubled performance. But there was no strong correlation between piplining-limit and performance gain.

Akka Team

unread,
Jun 1, 2015, 10:05:31 AM6/1/15
to Akka User List
Ok, I will look into it at some point, but currently there is a huge backlog we need to grind through first.

-Endre
Akka Team
Typesafe - Reactive apps on the JVM
Blog: letitcrash.com
Twitter: @akkateam
Reply all
Reply to author
Forward
0 new messages