2

I am building a program that tries to simulate real clients request to measure the "quality" of the service. I am trying to measure the maximum acceptable number of clients. In other words, how many clients my webserver is able to service at same time. I measure that "quality" using the response time of each request and the number of reloads. Then, I have 10 thousand threads executing at same time, but just doing request in a random time (to avoid all of these requests being sent at same time and causing a deny of service).

My question is how can I get the response time without being affected by switching threads? So far, the only way that I found to get that response time was by doing:

long starTime = System.nanoTime();
InputStream inputStream = this.conn.getInputStream();
long endTime = System.nanoTime();
double elapsedTime  = TimeUnit.NANOSECONDS.toMillis((endTime - starTime))/1000.0;

Where this.conn object is a HttpURLConnection.

The problem is that the threads can be switched right after getting the inputStream, and the endTime will not be accurate. It can get worst with even more threads.

How can I get the exact time that will not be affected by thread switching?

rafael
  • 43
  • 5
  • 1
    Why won't it be accurate? You seem to be attempting two mutually contradictory things: load-testing, and unloaded response time measurements. Make up your kid. – user207421 Apr 25 '16 at 23:22
  • It won't be accurate because it's about 10 thousand threads running this. Then, my thread can be switched right after getting the InputStream. In other words, it can be suspended for a while and when it starts running again, the time that it spent suspended will be added to end time. Therefore, my elapsed time will count not only the time to get the InputStream, but also the time that the thread was suspended. – rafael Apr 26 '16 at 00:22

0 Answers0