{"id":85055,"date":"2021-09-21T12:31:46","date_gmt":"2021-09-21T07:01:46","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=85055"},"modified":"2021-09-21T12:31:46","modified_gmt":"2021-09-21T07:01:46","slug":"advice-for-benchmarking-an-api","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/advice-for-benchmarking-an-api\/","title":{"rendered":"Advice for Benchmarking an API (Possible Deadlock Prevention)"},"content":{"rendered":"<p><span style=\"font-weight: 400\">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.<\/span><\/p>\n<p><span style=\"font-weight: 400\">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.<\/span><\/p>\n<h2><span style=\"font-weight: 400\">How is this Success Possible?<\/span><\/h2>\n<p><span style=\"font-weight: 400\">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.<\/span><\/p>\n<p><span style=\"font-weight: 400\">The APIs have to be managed throughout their lifecycle and monitored all the time to check their performance. This is where <\/span><a href=\"https:\/\/rapidapi.com\/blog\/api-management-vs-api-gateway\/\"><span style=\"font-weight: 400\">API management and API gateway<\/span><\/a><span style=\"font-weight: 400\"> 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.<\/span><\/p>\n<p><span style=\"font-weight: 400\">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.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">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?<\/span><\/p>\n<h3><span style=\"font-weight: 400\">Consistency<\/span><\/h3>\n<p><span style=\"font-weight: 400\">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 &#8211; including things such as other applications &#8211; your test results will be affected.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">Even though some people might argue that it would be better to use <\/span><span style=\"font-weight: 400\">Virtual Machines<\/span><span style=\"font-weight: 400\"> 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.<\/span><\/p>\n<h3><span style=\"font-weight: 400\">Understand Your Network<\/span><\/h3>\n<p><span style=\"font-weight: 400\">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.<\/span><\/p>\n<p><span style=\"font-weight: 400\">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.<\/span><\/p>\n<h3><span style=\"font-weight: 400\">Use a Single Machine for Every Task<\/span><\/h3>\n<p><span style=\"font-weight: 400\">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.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">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.\u00a0<\/span><\/p>\n<h3><span style=\"font-weight: 400\">Overloading Does Not Mean Capacity<\/span><\/h3>\n<p><span style=\"font-weight: 400\">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.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">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 <\/span><span style=\"font-weight: 400\">microservice logs<\/span><span style=\"font-weight: 400\">, you should be able to get a curve of the performance. This will indicate how your API performs.\u00a0<\/span><\/p>\n<h3><span style=\"font-weight: 400\">Preventing Deadlock<\/span><\/h3>\n<p><span style=\"font-weight: 400\">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.<\/span><\/p>\n<p><span style=\"font-weight: 400\">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.<\/span><\/p>\n<p><span style=\"font-weight: 400\">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 <\/span><a href=\"https:\/\/techvidvan.com\/tutorials\/python-advantages-and-disadvantages\/\"><span style=\"font-weight: 400\">advantages and disadvantages<\/span><\/a><span style=\"font-weight: 400\">.<\/span><\/p>\n<p><span style=\"font-weight: 400\">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.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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.&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":85057,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1744],"tags":[4332,4333],"class_list":["post-85055","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology","tag-benchmarking-an-api","tag-deadlock-prevention"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Advice for Benchmarking an API (Possible Deadlock Prevention) - TechVidvan<\/title>\n<meta name=\"description\" content=\"Applications Programming Interfaces (APIs) have revolutionized digitization in the business world. Learn advice for benchmarking API.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/advice-for-benchmarking-an-api\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Advice for Benchmarking an API (Possible Deadlock Prevention) - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Applications Programming Interfaces (APIs) have revolutionized digitization in the business world. Learn advice for benchmarking API.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/advice-for-benchmarking-an-api\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-09-21T07:01:46+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/09\/advice-for-benchmarking-an-API.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Advice for Benchmarking an API (Possible Deadlock Prevention) - TechVidvan","description":"Applications Programming Interfaces (APIs) have revolutionized digitization in the business world. Learn advice for benchmarking API.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techvidvan.com\/tutorials\/advice-for-benchmarking-an-api\/","og_locale":"en_US","og_type":"article","og_title":"Advice for Benchmarking an API (Possible Deadlock Prevention) - TechVidvan","og_description":"Applications Programming Interfaces (APIs) have revolutionized digitization in the business world. Learn advice for benchmarking API.","og_url":"https:\/\/techvidvan.com\/tutorials\/advice-for-benchmarking-an-api\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2021-09-21T07:01:46+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/09\/advice-for-benchmarking-an-API.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/advice-for-benchmarking-an-api\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/advice-for-benchmarking-an-api\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Advice for Benchmarking an API (Possible Deadlock Prevention)","datePublished":"2021-09-21T07:01:46+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/advice-for-benchmarking-an-api\/"},"wordCount":969,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/advice-for-benchmarking-an-api\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/09\/advice-for-benchmarking-an-API.jpg","keywords":["Benchmarking an API","deadlock prevention"],"articleSection":["Technology"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/advice-for-benchmarking-an-api\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/advice-for-benchmarking-an-api\/","url":"https:\/\/techvidvan.com\/tutorials\/advice-for-benchmarking-an-api\/","name":"Advice for Benchmarking an API (Possible Deadlock Prevention) - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/advice-for-benchmarking-an-api\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/advice-for-benchmarking-an-api\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/09\/advice-for-benchmarking-an-API.jpg","datePublished":"2021-09-21T07:01:46+00:00","description":"Applications Programming Interfaces (APIs) have revolutionized digitization in the business world. Learn advice for benchmarking API.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/advice-for-benchmarking-an-api\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/advice-for-benchmarking-an-api\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/advice-for-benchmarking-an-api\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/09\/advice-for-benchmarking-an-API.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/09\/advice-for-benchmarking-an-API.jpg","width":1200,"height":628,"caption":"advice-for-benchmarking-an-API"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/advice-for-benchmarking-an-api\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Advice for Benchmarking an API (Possible Deadlock Prevention)"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/85055","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=85055"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/85055\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/85057"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=85055"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=85055"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=85055"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}