Advice for Benchmarking an API (Possible Deadlock Prevention)

Applications Programming Interfaces (APIs) have revolutionized digitization in the business world. Today, businesses are using APIs to come up with new innovative solutions that meet the demands of both the businesses and their customers. Apart from this, APIs have made software development easy.

When building a new application, businesses do not have to build it from scratch. They can get an API that has the functionalities that they need then implement it. Take for instance the Uber application. When you launch Uber and order a taxi, the app uses Google Maps API to locate any available taxis near your location. You then accept the one that you need. All this seems like it is happening right within the Uber application, but on the contrary, the application is calling other APIs to make everything work seamlessly.

How is this Success Possible?

That notwithstanding, there is a lot of work that goes into making sure that these applications do what they are supposed to do. The APIs behind the success of these applications have to be developed following accepted standards and tests done to make sure that they meet their expectations.

The APIs have to be managed throughout their lifecycle and monitored all the time to check their performance. This is where API management and API gateway come in. API management is the process of building and publishing APIs while at the same time making sure that access is controlled, usage policies are enforced, usage statistics are collected and analyzed, and reports on performance are generated.

On the other hand, API gateway is a tool within API management that accepts all API calls and redirects them to the right resources to make sure that the returned response meets all requirements. These two are important in determining how successful an API will be. 

In addition to determining the success of an API, developers need to benchmark their APIs to check whether they perform the way they are supposed to. So, what should you look for when benchmarking your APIs?

Consistency

One of the ways of making sure that you get consistency when benchmarking your APIs is to test every time you can. This is because if there are any changes in your APIs, or even your system – including things such as other applications – your test results will be affected. 

Even though some people might argue that it would be better to use Virtual Machines when looking for consistent test results, this would mean adding more abstraction layers and running more processes on the host operating system. Using dedicated hardware will provide consistent results when benchmarking your APIs.

Understand Your Network

Before conducting any test when benchmarking your APIs, you need to know the capacity of your network. This is important in determining whether the network is limiting your tests or the APIs you are testing. There are many tools you can use for this, with one of the most common being Iperf3.

Having understood your network, you can use different tools such as the httperf to monitor traffic and ensure that your bandwidth does not limit your tests. This way, you will get accurate test results.

Use a Single Machine for Every Task

One of the most common mistakes developers make is generating their load on the same machine where they benchmark their APIs. This makes the test results unreliable since the load generator might use the same resources as the API, limiting its performance. 

It is, therefore, advisable to have different and dedicated machines for both the load generator and the API tests. You should also use a closed network when testing. 

Overloading Does Not Mean Capacity

When benchmarking APIs, developers use tools to generate loads. Some of these tools throw too much load to an API. They, however, indicate the amount of load thrown. Even though this might seem like a good thing especially when finding out how an API behaves when overloaded, it does not indicate the capacity of that particular API. 

This is because microservices are bound to lose a certain amount of capacity when exposed to more load than they can handle. Instead of doing this when benchmarking APIs, developers need to test their microservices at different higher loads and in progression. This should continue until the microservice reaches a certain capacity that it can no longer handle. Looking at your microservice logs, you should be able to get a curve of the performance. This will indicate how your API performs. 

Preventing Deadlock

Deadlock is very common with APIs. It happens when two APIs using the same resource try to prevent each other from using the said resource. When benchmarking your APIs, you need to check for any deadlock situations. If any exist, then you need to find a way to prevent them.

Deadlock in APIs can be prevented by making sure that you do not hold a lock when calling any foreign code. Foreign code refers to any code written by your API users, including things such as listeners and callbacks. This should be checked when benchmarking your APIs as it helps to eliminate some bugs that occur when the API is being used.

In conclusion, developers need to make sure that they use a programming language they are good at when testing their APIs since each one of them has its own advantages and disadvantages. For instance, one of the best web programming languages, Python, is known for its easy-to-use frameworks as well as its advantages and disadvantages.

Additionally, every developer needs to make sure that their APIs are thoroughly tested before being released. This is important in ensuring that the APIs meet their requirements and bugs that might occur later are eliminated. One way of doing this is through effective benchmarking of the APIs.