Rust is fast (super fast)
Designed by Freepik

Rust is fast (super fast)

In a previous article, I posted on LinkedIn (see here), I wrote about a highly available and scalable IoT solution based on bare metals servers (for those that feel Kubernetes/OpenShift or AWS serverless) is an overkill.

I based the testing on some old raspberry pi3s as I wanted to prove that you could get decent throughput with off-the-shelf cheap hardware.

I wanted to now do a comparison with the solution I built (using Golang) against a Rust implementation of the services. I found a Rust load balancer here, downloaded and cross-compiled it to the "armv7-unknown-linux-gnueabihf" target. I converted my microservices to rust using "actix, serde and json" crates to read and save the JSON payload.

I used the same layout as in the article I mentioned (see diagram)

No alt text provided for this image

I set up keepalive as shown and just replaced the load balancers and microservices with the arm rust versions. I then configured the load balancer "toml" file, and finally verified that the services were all ok using the /stats endpoint of the load balancer

{
? "total_connections": 0,
? "current_connections": 0,
? "total_bytes_tx": 0,
? "total_bytes_rx": 0,
? "backends": {
? ? "tcp3000_out": {
? ? ? "total_connections": 0,
? ? ? "current_connections": 0,
? ? ? "bytes_tx": 0,
? ? ? "bytes_rx": 0,
? ? ? "servers": {
? ? ? ? "192.168.0.24:8080": true,
? ? ? ? "192.168.0.27:8080": true,
? ? ? ? "192.168.0.26:8080": true,
? ? ? ? "192.168.0.25:8080": true
? ? ? }
? ? }
? },
? "frontends": {
? ? "tcp_3000": {
? ? ? "total_connections": 0,
? ? ? "current_connections": 0,
? ? ? "bytes_tx": 0,
? ? ? "bytes_rx": 0
? ? }
? }
}        

The next step was to set up the load tester, I found a Rust version here, downloaded and compiled it for x86_64 (as I was executing this from my Fedora laptop). I tried keeping the same concurrent settings (10) and set the requests to 2100, the load testing tool doesn't consider the requests as with the go-bench load tester version i.e for the go-bench it uses concurrent connections multiplied by the requests to give a rough throughput of 2100 requests.

I was amazed at the initial results, I got 2900 requests per second. I then experimented to see what were the limits, I found the optimal at 2100 requests with 40 concurrent connections

base: 'https://192.168.0.15:3000
iterations: 2100
concurrency: 40
rampup: 2

plan:

? - name: POST JSON
? ? request:
? ? ? url: /streamdata
? ? ? method: POST
? ? ? body: '{
? ?     "name":"iot-paas",
? ?     "deviceId":"id123444",
? ?     "patientId":"pid3423423",
? ?     "data":[
? ? ?     {
? ? ? ? ?   "hr":80,
? ? ? ? ?   "bps":120,
? ? ? ? ?   "bpd":80,
? ? ? ? ?   "spo2":96,
? ? ? ? ?   "custom":{
? ? ? ? ? ?   "tp":34.7,
? ? ? ? ? ?   "rr":20,
? ? ? ? ? ?   "etc":"123"
? ? ? ? ?   },
? ? ? ? ?   "date":"17-03-2023"
? ? ?     }
? ?     ]
      }'
    ? headers:
    ? ? Content-Type: 'application/json''        

Here is the output from the load tester stats view

No alt text provided for this image

6091 requests per second WOW, that's one massive improvement compared to the Golang version where I got 2100 requests per second. As I mentioned that this is running on 7-year-old architecture. The pi3s were released in?February 2016?with a 1.2 GHz 64-bit quad-core ARM Cortex-A53 and 1G RAM.

I am absolutely amazed at Rust, I would imagine that due to the fact that there is no garbage collection, the optimized compiled binary, the actix web framework (and more), all add to making it performant. I haven't looked at optimizing the microservices even further (i.e avoid JSON marshalling - using pure string buffers etc), but I don't need to I'm more than blown away by its performance !!!.

So I can say now without any bias "I'm officially a big Rust fan-boy" !!!

Marco Troisi

CTO @ Trilo ? Cloud Consultant ? Writer @ The Serverless Mindset ? AWS Community Builder

2 年

Considering that the previous Go implementation was already very fast, this is quite an astonishing result!?

要查看或添加评论,请登录

Luigi Zuccarelli的更多文章

  • Podman Executing Unikernels ?

    Podman Executing Unikernels ?

    I'm really big fan of Podman, as a team we are responsible for a component (oc-mirror) that does bulk copying of…

    8 条评论
  • Unikernel Platform As A Service

    Unikernel Platform As A Service

    We are extremely fortunate at Red Hat. We have the opportunity to work on technology that could benefit the open-source…

    3 条评论
  • Rust Everywhere

    Rust Everywhere

    Over the December break I decided to start looking at learning Rust, the main reason really is that I have been using…

    8 条评论
  • High Availability and Scalable IOT Edge Service using a Raspberry Pi Cluster

    High Availability and Scalable IOT Edge Service using a Raspberry Pi Cluster

    I built a cluster of Raspberry PI's (6 pi3s and 1 pi4). They are fairly old now (except for the pi4), I used them for…

    1 条评论
  • You gotta love Red Hat Universal Base Images (ubi)

    You gotta love Red Hat Universal Base Images (ubi)

    When working with Linux Containers, I create all images using centos8 for development (dev) and user acceptance testing…

    2 条评论
  • My disastrous technical interview

    My disastrous technical interview

    I was a bit reluctant to write this article because I felt I would be exposing myself. I have over 25 years of…

    14 条评论
  • Custom CICD pipeline with less than 1 minute end to end builds

    Custom CICD pipeline with less than 1 minute end to end builds

    I am a big fan of Tekton and was recently on a team that completed a proof of concept over a period of 2 months using…

  • Event based on demand IOT measurements

    Event based on demand IOT measurements

    In my last article I wrote about a gRPC microservice event service (without a message broker) based on a design…

  • Taking some design principles from kubernetes

    Taking some design principles from kubernetes

    I watched a video a while ago about a deep dive into kubernetes architecture. It covered a few principles but the one…

  • Using ML to score against the NEWS chart

    Using ML to score against the NEWS chart

    In my last article I wrote about a photoplethysmograph wearable device that measures 3 vital signs, namely blood…

    2 条评论