Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
October 29, 2020 02:49 am GMT

Is the pain worth the gain? Writing webapps in C (Benchmarks vs Flask and Nodejs)

I wanted to do a performance comparison between Facil(a web framework for C) against some more conventional tools, such as Flask(Gunicorn server) and Nodejs. Let's dive in!

download (7)

How the benchmarking was done:

  • A simple webapp was made using each framework. These webapps embed the client's IP address in a page template and then serve it to the client.
  • The 3 webapps were tested under light, medium and heavy load for 5 minutes each, running on a 1GB single core virtual machine(on Digital Ocean)
  • They were evaluated on response time, CPU and memory consumption.
  • In all of the plots below, the average value by Facil is shown as a dotted blue line for easier comparison.

TLDR;

  • If you are developing a high load web application(over 1000 requests per second), writing it using Facil could definitely pay its dividends over time when it comes to resource consumption, response time(latency) and the variance of these two factors(they tend to stay more predictable, even under a sudden surge in load)
  • For light load applications, Facil might be overkill(did not provide significant benefits) unless you are developing for an embedded platform or you prefer to develop in C compared to other languages

Heavy load (~1100 requests per second)

download (7)

Response Time

Facil has come out on top by far when it comes to latency under heavy load. Facil managed to:

  • Have less of a latency spike (it responded better to a sudden surge in load at the beginning of the test)
  • Have much less variance in response time (more reliable results)
  • Have a lesser average response time under heavy load

Resource Consumption

download (15)
When it comes to resource consumption, Facil also managed to:

  • Have lesser resource consumption in both ram and CPU, especially compared to Flask
  • Have a lesser variance in resource consumption compared to other frameworks

Medium load (~400 requests/sec)

download (12)

Response Time

Under medium load, Facil was:

  • still leading ahead of Flask in terms of response time, but Nodejs is catching up(Facil was arguably a tiny bit better though).
  • Facil still had a better response to sudden load in the beginning of the test than Nodejs

download (13)
In terms of resource consumption, under medium load, Facil:

  • Is still significantly leading in terms of RAM consumption ahead of both Flask and Nodejs
  • Had less of a CPU spike under sudden load
  • Had less variance in CPU consumption compared to the other two candidates

Light load (~100 requests/sec)

download (10)
Under light load, Facil:

  • Had seemingly no advantage in response time over the other frameworks

download (14)

  • Facil had some minimal advantage in RAM consumption compared to other frameworks

Final notes

Obviously this was just a simple test, but it has shown that if you are expecting large loads, want to keep hosting as cheap as possible by minimizing resource consumption, or doing development for embedded platforms, a non-conventional framework like Facil might be worth looking into.

You can find the source code for the 3 webapps under:

GitHub logo wickdChromosome / simple_webapp_comparison

Repo for article comparing writing webapps in C, Flask, Nodejs


Original Link: https://dev.to/wickdchromosome/is-the-pain-worth-the-gain-writing-webapps-in-c-benchmarks-vs-flask-and-nodejs-14l0

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To