In continuation to my earlier post about using Rust Language for sustainable cloud computing, here, in this post, I would like to present comparison of facts like the CPU & Memory utilisation by languages like C#, NodeJS, Java, Go & Rust on k8s.
To perform this comparative study, I developed very basic Rest Api's in all these languages that serve exactly similar kind of data. All these Rest Api's are built based on the project template of ASP.Net Core Web Api, yes, the WeatherForeCast, containerised, deployed to Kubernetes and exposed using NGINX Ingress Controller.
Frameworks Used
Language | Framework |
---|---|
C# | ASP.Net Core |
Java | SpringBoot |
Node | ExpressJS |
Go | Fiber |
Rust | Warp |
Test Environment;
k8s Deployment Resource Limits;
Language | Request CPU | Request Memory | Limit CPU | Limit Memory |
---|---|---|---|---|
C# | 250m | 32M | 500m | 64M |
Java | 250m | 128M | 500m | 256M |
Node | 250m | 32M | 500m | 64M |
Go | 250m | 32M | 500m | 64M |
Rust | 250m | 32M | 500m | 64M |
Stress Test Parameters
- Threads - 12
- Connections - 400
- Duration - 30 Seconds
Stress Test Results
Language | Total Requests | Throughput | Data Received | Transfer Rate |
---|---|---|---|---|
C# | 451463 | 15006/sec | 288MB | 9.56MB |
Java | 57992 | 1928/sec | 41MB | 1.35MB |
Node | 104504 | 3472/sec | 67MB | 2.23MB |
Go | 595449 | 19815/sec | 392MB | 13.05MB |
Rust | 672391 | 22344/sec | 467MB | 15.52MB |
Resource Utilisation in Idle and Stressed State
Language | Idle CPU | Idle Memory | Stressed CPU | Stressed Memory |
---|---|---|---|---|
C# | 1m | 35Mi | 483m | 45Mi |
Java | 1m | 129Mi | 500m | 228Mi |
Node | 1m | 30Mi | 500m | 41Mi |
Go | 1m | 7Mi | 465m | 17Mi |
Rust | 0m | 0Mi | 352m | 9Mi |
Observations
All the Rest Api's that I deployed to k8s, k8s was able to spin up the pods, but not Java SpringBoot based Rest Api pod. k8s was failing to spin up the Java SpringBoot based Rest Api pod for [OOMKilled] error, I had to then increase the memory from request 32M to 128M and limit from 64M to 256M. Despite the fact that SpringBoot deployment was configured with more memory than other deployments, its worst in throughput.
To my pleasant surprise ASP.Net Core pod was able to run with request memory of 32M and limit memory of 64M and much better throughput as compared to SpringBoot. Microsoft has definitely done a tremendous job at improving .NET Runtime in terms of the memory requirements and its utilisation even the garbage collection post stress test was faster than Java.
In an idle state all the frameworks were consistently eating up 1m core of CPU and that's the need of GC background thread, where as Rust was 0m.
Go Fiber implementation was somewhere closer to Rust Warp implementation from throughput perspective, was consuming close to 25% more CPU.
Node Express based Rest Api was much better compared to SpringBoot based Api, almost double the throughput.
What can you build using Rust?
Rust can be used to develop applications for cloud, Microservices, Azure Functions, AWS Lambdas. There are number of Rust Crates (packages) available to build applications for cloud, some of the widely used ones are listed below.
Web Frameworks
ORM
Database Clients
- SQLX (supports MS Sql, MySql, PostGres & SqlLite)
Additionally, both Amazon and Microsoft has sdk for Rust to utilise services from their respective cloud platforms. Microsofts Azure sdk for Rust is part of Azure organisation on GitHub, but it's, still under heavy development and not official yet.
Is it easy to adopt Rust?
No, not at all, Rust is a language that has a very steep learning curve, lot of new stuff at conceptual level.
Not very long ago, Java too, was considered little difficult adopt for people who were trying to shift from procedural languages to Java. But with proper trainings and mentoring, people gained the required level of skills, so, the same is applicable to Rust.
Conclusion
As you can clearly make out from the about test results, that Rust outperforms every other language & framework in both throughput and resource utilization.
Languages like, Java, C#.NET, JS on Backend have served their purpose in an era where the world was getting into the internet based apps from desktop based apps. Now, that most of the IT workloads are moving to Cloud, it has become imperative to use modern languages like Rust that uses less resources, saves compute cost on cloud and more importantly, emits less carbon which results in to a lesser impact to our planet.
You can get all the source code and k8s manifests in my Git Repository, request me in comments for the same.
Top comments (0)