12/28/2023 0 Comments Go http benchmarkA few salient features FastAPI brings like Automatic data model documentation, JSON validations, serialization and more. Remember, good Go devs are hard to find compared to Python & JavaScript devs (at the time of writing this article) simply because these languages and their ecosystem have been here for longer. Factors like existing software stack, dev skills & experience in the team will play a significant role in making such decisions. However, this doesn't mean that you no longer use Python or NodeJS based frameworks. Express (NodeJS) is ~1.5x faster than FastAPI(Python) and, these frameworks are ~7.5 and ~11.35 times slower than Fiber ( as per multi-core async performance). Let's get to it, shall we?įiber (Golang) is way ahead of the game in terms of speed and raw performance. Well, it is going to be a long one and yet may not be complete. Yes, that's how Sync & Async works and, since we are dealing with computers and not humans, they always perform actions as instructed! Our thoughts. The opponents are external DB or service/APIs with which the RESTful service will communicate. Now swap the crazy madness of a guy playing chess with multiple people with a RESTful service. It continues till the last move of the last remaining game. over 1.6 hours) #Approach 2 - Dave plays all players at once! How is that possible? Every time an opponent takes time to think about their next move, Dave moves on to the next player and the next. What do Sync and Async mean? Dave is also a champion chess player and, he has been challenged to play chess with not one but ten different players all at once! He has essentially two approaches #Approach 1- Dave decides to play one player at a time and, if the average time per game is 10minutes (assuming other players are making quick decisions like our champ!), even then it takes 10 mins X 10 players = at least 100 minutes (i.e. However, Fiber is still ~7.5 and ~11 times faster than ExpressJS and FastAPI. FastAPI Async with 4 workers on 4 Cores ExpressJS Async with 4 workers on 4 CoresĮxpressJS is 1.5x faster than FastAPI. Let's see how they perform when running on all CPU cores. Now, you may be wondering Golang is using all CPU cores, but FastAPI and ExpressJS are utilizing only one CPU core per instance. Now comes our star performer - Fiber (Golang)įiber takes less than a second to process 5k requests! Since Fiber framework is implemented in Golang, concurrency is handled out of the box which means there is no need to specify async await syntax in your code. In both frameworks, we see a single-core performance. Again, we must note that FastAPI and Express JS apps are running on one worker by default. Express JS (Async) - NodeJS ExpressJS AsyncĪ similar trend is apparent in asynchronous mode, ~509 requests per second. Express JS (Sync) - NodeJS ExpressJS SyncĮxpress JS in the synchronous mode does 447 requests per second which are over ~2x jump from the FastAPI. If we tweak the worker count to the number of available CPUs, there should be a significant jump in the performance. One important thing to point out, that we are running FastAPI's ASGI server (uvicorn) with default settings (1 worker). FastAPI (Async) - Python FastAPI AsyncįastAPI in asynchronous mode clocks in at ~228 requests per second. FastAPI (Sync) - Python FastAPI SyncįastAPI in synchronous mode clocks in at ~178 requests per second. We will start with FastAPI, followed by ExpressJS and then Fiber. The entire testing session ran for a few minutes and, we have the results in the below screenshots. One could tweak these numbers as per requirements. Ryzen 5500U (6 Cores & 8 GB DDR4 3200 MHz RAM)Īnd the test - ab -k -c 350 -n 5000 The above command sends 5k requests in total with a concurrency of 350 requests.Benchmarks make sense as long as you test them on the same hardware environment. Well, you could run this benchmark on any compatible system. The beauty of micro-services is that different teams could write services backed by business logic in whichever programming language & Eco-system conducive to their use case. In this article, we will load-test three REST API frameworks written in NodeJS, Python & GoLang and, the benchmark will be using the Apache Benchmark tool. Dave's task is to figure out how services like order, checkout and other product-related services would perform in such situations. The marketing team wants to run a big flash sale for a couple of days and expects a massive influx of online traffic to the website and the mobile app. ![]() Are your RESTful services ready to handle a surge in traffic? One way to find out.ĭo you know if your RESTful services will take the heat when your service/website gains multi-fold momentum in traffic? Dave works for an eCommerce startup, one day, he was given a task to find out if the micro-services which he has been writing is scalable and optimized.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |