...

/

The Estimation of Response Time of an API

The Estimation of Response Time of an API

Learn to estimate response time of an API generally, as well as for different data sizes in an API message.

Please remember that the response time of an API is calculated using the following equation:

If we consider the processing time as 4 ms, as estimated here, and the latency of a GET request as 331.42 ms, as calculated here, the total response time of the GET request will be as follows:

Point to Ponder

1.

Let’s assume someone asks a team to build a WWW search engine. Now, that team can use simple experiments to determine how much time a search API call takes on the Google server. Say it’s a few milliseconds. We have a ballpark target number for a new product to compete with Google Search; why do we use a complex method to calculate the response time, as we’ve explained in this chapter?

Show Answer
Q1 / Q1
Did you find this helpful?

Now, let’s estimate the response time of APIs for varying data sizes in the subsequent sections.

Motivation

In this section, we’ll perform some trials using the Postman tool. The goal is to formulate a method to calculate the average response time per kilobyte of a message. Once we have the average response time per KB, we can estimate the plausibility of our API designs in terms of latency. We know that it is not possible to calculate an accurate average response time per KB. The time varies due to different factors involved in the request and response. These factors involve the base time, transfer start time (sum of RTT and processing time), and download time of any request. Network congestion, data transfer technologies, and service provider variations can all affect these factors. Moreover, we’ll use cold start requests for every trial, where base time does not cache, and the server will need to get all the information again.

Using our calculations, we’ll obtain a range of response times that can be used in our design problems. But the estimated numbers can vary depending on the changes in the factors mentioned earlier, which are mainly due to load conditions on the network or the back-end services. The following equation is just a reminder of how we calculate latency:

Let's look at how we estimate response time.

The GET request response time

For a GET request, the download time is the main factor that changes according to varying data sizes. It is because the average value of RTTgetRTT_{get}​ remains the same (for an optimized bandwidth) regardless of data size. We’ll focus on estimating how the download time is affected per KB. For that, trials are repeated for a single request to get an average download time (a factor affecting the latency in a GET request). We calculated the mean and the standard deviation in download time for varying data sizes, as depicted in the following table:

GET Request Trial Results


Download Time

Response Size

Trial 1

Trial 2

Trial 3

Trial 4

Trial 5

Mean with SD

1.3 KB

2.44 ms

3.46 ms

3.39 ms

3.02 ms

2.56 ms

2.97 ± 0.47 ms

2.5 KB

5.15 ms

4.65 ms

2.45 ms

2.51 ms

3.19 ms

3.59 ± 1.24 ms

28 KB

6.27 ms

4.19 ms

2.57 ms

7.78 ms

4.53 ms

5.06 ± 2.01 ms

155 KB

60.63 ms

67.14 ms

61.6 ms

64.82 ms

57.11 ms

62.26 ± 3.87 ms

The following graph indicates how the download time changes with the increased size of the response:

The changes in the download time for GET request with varying response size

It is important to mention that to derive a practical number for a GET request, we have to find the download time per KB, which will be used as a standard number to find the time ...