Think Time and CPU Usage in Performance Testing

Sayantani Ray
5 min readAug 24, 2020

What is Performance Testing?

We all have experienced slowness while browsing through a particular online application. While it could generally be due to interruption in the internet services or the network, but it could also mean that the overall response time of the application is slow. In order to check the response and stability of a web application under varying loads, Performance testing comes into picture.

In other words, Performance testing is basically checking the speed of the application, the crash point of an application while continuously putting varied load.

Another aspect of Performance testing is to make sure resource utilization is under control. For example, a web application may take up to 100% CPU utilization if not optimized properly and this could result overall slowness in a customer’s system. Consequence — bad reputation and sales goal is not met. Proper Performance testing could omit this issue and hence this type of testing is required.

There are various types of Performance testing that can be planned and each has separate set of goals. In this article, we will focus more on a very common problem that a tester may face and without the proper solution, the performance testing may fail or it will not provide the desired result. With the below scenario I am trying to point out that to run Performance testing, one should consider the mandatory parameters, if one such parameter, Think Time is missed then it can lead to failure of Performance test.

CPU Usage — Issue in Performance Testing

The issue that I am talking about is related to CPU usage and it’s hitting to 100%. I noticed 100% CPU utilization in my performance script, using Visual Studio tool, in certain iteration. The page response time, the transaction time were all absurdly high and even the manual tests performed at the same time when the load was put, showed some notorious page response time. The worrisome part was definitely CPU usage standing at 100% and HHTP 429 error which indicates that too many requests have been sent in a given amount of time.

After doing a bit of R&D, I got to know tweaking Think time can help in resolving the issue or I can say Think time stopped the issue from occurring.

Now let us look at what is Think Time in Performance Testing.

What is Think Time in Performance Testing and why do we use it

As the name suggests, Think time is the time taken to think. Now, when a real-time user performs any action in a web application, he or she takes some time to do activities such as reading the content, typing a user id, password, or may be inserting data in some form. The time gap between actions, say 5 secs, so 5 secs would be Think Time. So, Think time is the time taken by any user to think in between two consecutive actions.

To simulate the similar type of action a Performance tester includes the Think Time in each request in the script. This Think Time will create the delay in the test environment that a real-time user does while navigating through a web application.

How Think Time is related to CPU Usage?

There is another reason to introduce Think Time in Performance test. Without Think Time when a Performance test is run, thousand of requests get bombarded to the server without any pause. This situation makes the CPU think that it is a threat and CPU becomes too busy to handle the threat and increases its capacity to 100%. As a result, the server may fail and overall page response time increases. Due to this the Performance tester will not achieve the desired result.

Adding Think Time in between requests will halt the virtual users for a defined period of time and the CPU will not consider the requests as threats. This will help servers to process the requests without confusing the CPU and emulate Production like result.

That is how my issue with CPU usage got resolved by adding Think Time in between the requests. After adding Think Time of 10 secs in between requests (27 requests) of my scripts, the CPU usage reduced to 20–25% which was a mirror reflection of Production environment.

Now let us see where and how do we add Think Time in Performance Test script

Where Think Time is added

Think Time is added in between two requests or transactions. For example, a real-time user logs in to Facebook, performs a Search and Logs out, so here are three transactions, so Think Time should be added two times in between the transactions:

Log In to Facebook ->THINK TIME->Search in FB->THINK TIME->Log Out

How is Think Time calculated

Think Time depends on the size of the content; generally it should be in between 1 secs to 10 secs. Think Time extends the session of a user on the server, so it should be noted that Think Time shouldn’t be too large as it can restrict the user from creating a new session on the server. It shouldn’t be too less too, as the concurrency of the users will be interrupted. Scripts without Think Time should not be considered as it would create the issue that we discussed above.

Calculating Think Time can be a little confusing for any Performance tester as the parameters to calculate think time should be in equivalent units of measurement. Many online calculators are available over the internet but most of them are faulty and doesn’t provide accurate result. I feel it is better to do some trial runs and by changing Think Time based on the content of a particular page can help. For example, if the first transaction is Login page and next is an Article page, then obviously the Think Time should be higher as a real-time user will take few minutes time to read an article.

A little dry run with multiple Think Time can help in achieving the target result.

--

--

Sayantani Ray

Software Test Engineer by profession, a dancer by passion and a wishful thinker on mind