last day (15 days later) » 

18:28
1
A: How to improve the performance while using ExecutorService with thread timeout capabilities?

Peter Lawrey then run the program again it will start giving me 95th percentile as 3 ms. So not sure why end to end flow gives me 95th percentile as 14-15 ms You are generating the tasks faster than you can process them. This means the longer you run the tests, the further behind it gets as it is queuin...

Thanks Peter for the suggestion.. There is one very strange thing I would like to tell you.. May be that can give you some clue - One thing I found very strange here is, if I comment out line 1 and line 2 in DemoTest class and uncomment line 3 and line 4 in Task class and then run the program again it will start giving me 95th percentile as 3 ms. So not sure why end to end flow gives me 95th percentile as 14-15 ms?
Yes exactly Marko.. Thank you for making it very clear..
You also have an increased delay from starting the threads. Your code won't be compiled until it is executed 10,000 times and I normally ignore the first 10K or first 2 seconds of a benchmark.
@PeterLawrey To answer on that question. I have already ran it couple of time before measure it.. Currently I am running 500 times for warming up then I start measuring the call as shown in my DemoTest class. I can increase the warmup number to see whether it affects any performance or not..
@Webby It occurs to me you are generating requests faster than you are processing them so they are queuing. A longer run should appear to be slower as the queue will get longer. See my answer.
@PeterLawrey I see, so in short you are saying, I should sleep for couple of milliseconds before making any call to my getData method?
18:28
@Webby if you slow down the producer, e.g. add Thread.sleep(1) after each call, you should see better numbers. You wouldn't do this in reality which is one of the hazzards of trying to benchmark this system. I suggest turning the problem around and say measure fast can you send requests and ensure 99% are less than 10 ms.
@Webby and I would run the test for at least 10 seconds, ideally an hour or over night.
Let me try that.. But in general in production, will the call be coming at a difference of 1 ms from the customer to my code..? If not, then again it will be a problem on my side.. Right?
If you are trying to use any service which cannot keep up, you can have requests timeout before they have even been sent.
because that service is still trying to handle previous requests.
I see... This is what I have tried as per your suggestion..
	   public static void main(String[] args) {

			URLTest bc = new URLTest();

			// little bit warmup
			for (int i = 0; i <= 1000; i++) {
				bc.getData();
			}

			for (int i = 0; i <= 500; i++) {
				TimerTest timer = TimerTest.getInstance(); // line 1
				bc.getData();
				timer.getDuration(); // line 2

				Thread.sleep(1); // sleeping for 1 ms
			}

			// this method prints out the 95th percentile
			logPercentileInfo();

		}
warmup time going to 1000 rounds
and sleeping for 1 ms.
i think you should first try the obvious: making RestTemplate static
Ohh yeahh..
let me do that as well.
18:36
If this "fixes" the problem it shows that you have a queuing issue because your service cannot keep up. Your 3 ms timing is not correct because it only times how long that request took, not how long it had to wait to even start.
I don't know what to say now..
After changing to static RestTemplate
with a sleep of 1 ms
in between as shown in the above code
I get 95th percentile as 3 ms
I am confuse why??
but that is exactly what I expected
why is it confusing?
you now have the same measurement "on the inside" as "on the outside"
In short RestTemplate should be static?
You are slowing down the producer so the queue never builds up and you get the same timing as you get for each request. Try taking out the sleep and run 5000 instead of 500 and I expect you will see over 50 ms.
It has nothing to do with restTemplate being static.
18:38
@peter but he is wating for a request to cemplete
In both cases yes.
only if the request takes more than 100 ms do they start building up
so there's no queueing issues unless the requests are really slow
The queue starts building as soon as you start.
The requests are really slow. They take 3 ms.
btw before RestTemplate was static, webby was recreating the whole connection pool for each request
How long does it take to add to the queue? less than 3 ms.
18:39
and wasn't even closing it
but he doesn't add to the queue before getting the result of the previous future
@MarkoTopolnik good point. Hmmm.
So the thread pool is rather pointless.
he is basically doing everything synchronously unless there is a 100 ms timeout
Yeah exactly..
And peter, I did same exercise
Removed the sleep and added 5000 iterations
18:41
SO the problem is more likely to be as you say; because it is creating a new connection each time.
	   public static void main(String[] args) {

			URLTest bc = new URLTest();

			// little bit warmup
			for (int i = 0; i <= 1000; i++) {
				bc.getData();
			}

			for (int i = 0; i <= 5000; i++) {
				TimerTest timer = TimerTest.getInstance(); // line 1
				bc.getData();
				timer.getDuration(); // line 2

			}

			// this method prints out the 95th percentile
			logPercentileInfo();

		}
I get 95th percentile as 4 ms
So I think Marko is right
btw the instantiation of the RestTemplate was throttling the request rate much more than that sleep(1)
Sorry, I missed that despite the thread pool, you were only using it in case of a timeout.
So my first thought was that each connection was taking up to 20 ms to create.
RestTemplate, even at its default configuration, maintains a connection pool
however my advice to OP is to check out alternative configurations
So might be another question on this... Is this the way I should be using RestTemplate? or might be some better way of doing it, like closing it and doing other things as well w.r.t to my currenrt example..
18:44
the default is to use JDK's URLConnection
how about ObjectMapper?
you should use an explicit ConnectionFactory, i think
restTemplate by itself isn't closeable
ObjectMapper is fine
it doesn't involve native resources
by explicit ConnectionFactory you mean to say wrapper around JDK URL connection?
Jackson is really the best choice for professional-grade JSON
no, just check out the docs
Spring comes with ConnectionFactory implemntations
which you pass as a constructor argument to RestTemplate
the other option is based on Apache HttpClient
In a project I did, I didn't go for Spring RestTemplate; I went for Jersey Client
I see.. And here Jersey client you talking about is ObjectMapper or some other client.. Sorry for my little knowledge on these things..
18:48
Jersey is an implementation of JSR-somethig
it is a full-stack REST implementation
both client and server-ide
but there are separate JARs for client
it also uses Jackson ObjectMapper
but not by default :)
anyway, potato-potahto
stick with restTemplate
Sure.. You suggested me couple of options.. Whihc one should I go with..
Should I stick with RestTemplate
by making it as static
go with resttemplate, but don't use the default contructor
or you want me to improve something on that..
take control of the connection factory
using a static restTemplate could have issues
are you using a Spring IoC container?
if yes, then obviously you would let Spring handle the singleton lifecycle of the resttemplate
if not, then you probably have a minimalist application architecture
and a static resttemplate may be an OK option
teh trouble with such a simple design is that you lose control over when exactly you initialize the resttemplate
but you can fix that by using an explicit initialization method
Actually we have a framework in our company which is based on Eclipse... And it is on Spring but not sure whether it is Spring IoC container..
need to check with them..
18:53
you are bulding an Eclipse RCP application?
or you are building the application with eclipse as IDE?
I am building an application on the framework which is built on Eclipse IDE
which uses Spring Container If i am not wrong..
i didn't understand you
what does it mean that the framework was bulit on Eclipse IDE?
meaning, i am building an application on Eclipse in short..
As eclipse is open sourced..
So they have use Eclipse JUNO
to modify it slightly and cater to my company needs
that sounds like an Eclipse RCP application
And made a new Framework from that which is 99% similar to Eclipse
18:57
they are bulding Eclipse plugins?
with some extra features related for our use..
No, it is just for our internal use
:)
to make the deployment easier
that's all.
no, that's a technical question
eclipse rcp apps are built as a set of plugins
but anyway, beside the hpoint
I se..
spring can be used with an rcp app, but not trivially
sure.. I will take a look into that..
Anyways, I will try to see how we can use RestTemplate better.. If you have any example which shows how to use RestTemplate with ConnectionFactory, then it will help me a lot..
Currently I am not able to find that somehow..
19:07
there's really not much to it
fac = new CommonsClientHttpRequestFactory();
template = new RestTemplate(fac);
and you can fac.destroy() when you're done with it
okk
this is something which you weren't able to do with your current code
but this class is deprecated
I guess
after taking a look on the google?
i'm looking at 3.0 docs
i don't see deprecation
but anyway, if they have a newer one, use that
it will be the same.
Sure..
let me try those stuff.. And see how it goes.. Thanks a lot for the help..
19:09
that's what i was looking at
alright, let's call it a day
bye
sure.. thank you..
19:36
@Peter, coming back to your question.. I am using ExecutorService to have the timeout feature, meaning if any call is taking some time to respond, then timeout the call..

last day (15 days later) »