vertx as a proxy performs as good as nginx

3,418 views
Skip to first unread message

javadevmtl

unread,
Nov 13, 2013, 5:09:01 PM11/13/13
to ve...@googlegroups.com
Just so people know that vertx is pretty capable :) Though I'm sure no one in this forum doubts it :p

Been looking at building a custom proxy or use nginx as a proxy.

I wrote my proxy using vertx-1.3.1 though I will be switching to 2.1M1

The numbers are on par. So I have to say pretty impressive.

Although I will probably use nginx because of the load balancing and reverse proxy features.

Though been using vertx for everything else http :)

Created a vertx 2.1 http application cache backed by EHCache and have been able to test up to 90,000 request/responses per second (16 core hyper-threaded server vertx -instances 32) at 2ms response times (this includes network time) and I'm sure it can do more, I ran out of client machines (1000 JMeter users spread over 5 client machines)
The same vertx application can do about 50,000 request/responses per second on a 4 core server.
The application is simple. Receive request, store it to cache (no log to disk), reply with "Added". Same goes for getting the cache value.

Vertx and Java perform pretty damn good if you ask me :)

El Gazali

unread,
Nov 13, 2013, 5:33:21 PM11/13/13
to ve...@googlegroups.com
Awesome! 

Leng Sheng Hong

unread,
Nov 13, 2013, 6:33:05 PM11/13/13
to ve...@googlegroups.com
Good to know the rps on 16 core!
I too just wrote a proxy which is built into the web framework i m working on.

Tim Fox

unread,
Nov 14, 2013, 3:34:03 AM11/14/13
to ve...@googlegroups.com
Awesome! And it will be significantly faster using 2.1 :)

Have you considered contributing your proxy as a module? Even if it's
not complete that's fine - people could build upon it. Would be great to
have an end-end Vert.x solution which avoided the need for third party
load balancers.
> --
> You received this message because you are subscribed to the Google
> Groups "vert.x" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to vertx+un...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Tom Carchrae

unread,
Nov 14, 2013, 7:52:36 AM11/14/13
to ve...@googlegroups.com
Here's a gist of my proxy code: https://gist.github.com/carchrae/7466073  (using 2.1). A vertx snips website would be quite handy.  I don't feel like this gist is worthy of a module.  

The (somewhat poorly named) ClientGetter interface could be used to do load balancing.  I just used it to avoid cluttering up the proxy code with the server details.  

Routes is just RouteMatcher extended with a few utilities (which are not used here).  This example catches a few routes, and is also used as a fallback (no routes matched on vertx, check the proxy).

I would love any feedback on it.  I wrote it to avoid Same Origin issues.  

I do have a question:  You may notice in the example ClientGetter I create a new HttpClient for each proxy request - I found that if I did not do that, sometimes the response would not be for another request!  Sorry I didn't dig into that further (or report it until now).  I thought perhaps this was by design (or rather, I was abusing HttpClient).

Tom





To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.

Tom Carchrae

unread,
Nov 14, 2013, 8:00:28 AM11/14/13
to ve...@googlegroups.com
I do have a question:  You may notice in the example ClientGetter I create a new HttpClient for each proxy request - I found that if I did not do that, sometimes the response would not be for another request!  

gah - bad editing.

^ sometimes the response received would be for a different request!  

kim young ill

unread,
Nov 14, 2013, 12:09:23 PM11/14/13
to ve...@googlegroups.com
cool, thanx,
how does the httpclient ( works as proxy) handle the "connect" from browser to tunel the connection to remote server ? 



--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.

Tom Carchrae

unread,
Nov 14, 2013, 1:05:30 PM11/14/13
to ve...@googlegroups.com
On Thu, Nov 14, 2013 at 9:09 AM, kim young ill <khi...@googlemail.com> wrote:
cool, thanx,
how does the httpclient ( works as proxy) handle the "connect" from browser to tunel the connection to remote server ? 

See the gist: https://gist.github.com/carchrae/7466073#file-proxy-java-L125 - or perhaps explain your question more.

It could probably be improved to write the buffer incrementally.

Tom


Message has been deleted

kim young ill

unread,
Nov 14, 2013, 3:32:37 PM11/14/13
to ve...@googlegroups.com
thanx for all the responses, but i mean sth different here,
it's clear with the requests over plain http. but thing is different with https.
assume the httpclient works as a https proxy, when the browser wants to go to htps://www.google.com, httpclient will get this as command: CONNECT www.google.com:443, client should returns 200 to browser & then work as a pipe between browser & googe.com:443 (which is over ssl).
so the first thing i can see in httpclient is that i cannot send 200 back to client without
"destroying" the response (after end() the response will not be avail), but on the other hand, browser is wating for 200 & then will attempt to make the handshake over that connection with httpclient  & it assumes the other end will be www.google.com (since httpclient is working as a pipe right now). (correct me if i'm wrong here)

look at the api of the client i dont see any possibility to do such things.

httpclient.connect(...) will, infact, send CONNECT www.google.com:443 direct to google, which of course will fail (google server reject with not_supported)


thanx



On Thu, Nov 14, 2013 at 7:17 PM, John Smith <java.d...@gmail.com> wrote:
Here is an overly simplified example but it should give you an idea...





--
You received this message because you are subscribed to a topic in the Google Groups "vert.x" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vertx/kPfizM4ZVKo/unsubscribe.
To unsubscribe from this group and all of its topics, send an email to vertx+un...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

javadevmtl

unread,
Nov 15, 2013, 5:01:18 PM11/15/13
to ve...@googlegroups.com, khi...@googlemail.com
No exactly.

1- The browser will connect to your HTTPs server verticle using ssl and wait for a response.
2- Your server verticle will parse and read the HTTP request: headers, body etc...
3- Your server verticle will then use the HttpClient API to open a connection to the remote server. The connection can be HTTP or HTTPs it can even be TCPI/IP, UDP, Magic Protocol Z it doesn't matter. Vertx does not pipe the browser directly through to the HttpClient APIs. You have to explicitly program this logic, you can even do extra custom logic what ever your heart wishes. This is how a reverse proxy works.
4- Your server verticle will formulate a new message based on the headers and body it received from the browser and it will use the connection it opened in step #3 above to send the request.
5- Your server verticle will receive a response from the remote server.
6- Your server verticle will formulate a response based on the headers it received back from the remote server.
7- Your server will reply back to the browser with appropriate status code.

All this should happen really fast in fact the proxy should barely add any latency. The total response time will depends on the remote server and how long it takes to respond.


Then your server verticle can pick

Winston P.

unread,
Dec 15, 2013, 2:35:25 PM12/15/13
to ve...@googlegroups.com
I am wondering if someone managed to get similar performance on 2.1. I did a small test with the example proxy ProxyServer.java and Server.java om 2.1M2. I stripped all System.out.println calls and did two tests:

1. Jmeter --> ProxyServer.java --> Server.java
2. Jmeter --> Apache mod_proxy --> Server.java

I used a modest load of 10 current threads and a wait of 50 ms after each request in order not to run into cpu constraints on my laptop (i7). Results:

avg [ms] min [ms] max [ms] std dev req/sec
vertx proxy 9 5 101 3,445361 166,9784
apache 4 2 50 2,257866 183,8878

Apache is adding on average about 2 ms to each request, the vertx proxy about 7 ms. I am not saying this is bad performance, but I am hoping I to get to the same 2 ms as the original post.

Some additional data:
- vertx ran with 10 instances
- httpclient maxpoolsize = 10

John Smith

unread,
Dec 15, 2013, 6:03:29 PM12/15/13
to ve...@googlegroups.com
It's possible I'm using bigger boxes... My desktop is a quad core hyper threaded so 8 and the server is 16core hyperthreaded.

Also how much data are you sending. I was sending maybe 50-60bytes per request. Not including the HTTP headers.


Tim Fox

unread,
Dec 16, 2013, 4:04:23 AM12/16/13
to ve...@googlegroups.com
On 15/12/13 19:35, Winston P. wrote:
I am wondering if someone managed to get similar performance on 2.1. I did a small test with the example proxy ProxyServer.java and Server.java om 2.1M2.

Can you show me the code?

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.

Winston P.

unread,
Dec 16, 2013, 10:32:22 AM12/16/13
to ve...@googlegroups.com
Code is attached. 

It is a near exact copy of the examples with the changes indicated earlier:
- commented out System.out.println calls
- set maxPoolSize to 10
ProxyServer.java
Server.java
Reply all
Reply to author
Forward
0 new messages