Categories
Hardware performance python python performance virtualisation

CPU and FastAPI Performance

When migrating a FastAPI and WordPress website to a different VPS (virtual private server) provider it was noted that response time and requests per second were impacted negatively.

Response times were 2 times slower.

It was then noted that the cpu performance could be playing a big factor in this difference in performance.

In this post an exploration into cpu performance and fastAPI performance is made on different setups.

Disclaimer: Performance testing should be run on a real world scenario for the best choice – decisions should not be made on generic benchmarks.

The Setups

  • 2 CPU hostking VM (VPC) – R220 a month
  • 2 CPU cloudafrica VM (VPC) -R220 a month
  • 2 CPU digitalocean VM (VPC) – $18 a month
  • Raspberry Pi 4 Model B (4 GB RAM)
  • Desktop PC with a i5-3570k CPU

CPU Info

hostking:

Architecture:           x86_64
CPU(s):                    2
Core(s) per socket:   1
Socket(s):                2
Stepping:                 2
CPU MHz:                 2799.998
BogoMIPS:                5585.99

cloudafrica:

Architecture:            x86_64
CPU(s):                     2
Core(s) per socket:    2
Socket(s):                 1
Stepping:                  1
CPU MHz:                  2799.998
BogoMIPS:                  5599.99

digitalocean:

Architecture:            x86_64
CPU(s):                     2
Core(s) per socket:    2
Socket(s):                 1
Stepping:                  2
BogoMIPS:                 3990.62

raspberry pi:

Architecture:              aarch64
CPU(s):                       4
Core(s) per socket:      4
Socket(s):                    1
Stepping:                     r0p3
CPU max MHz:             1500.0000
CPU min MHz:              600.0000
BogoMIPS:                    108.00

desktop pc:

Architecture:                 x86_64
CPU(s):                          4
Core(s) per socket:         4
Socket(s):                       1
Stepping:                        9
CPU MHz:                       1600.000
CPU max MHz:                3800.0000
CPU min MHz:                 1600.0000
BogoMIPS:                       6784.09

Sysbench

2 threads

Running sysbench --threads=2 cpu run. Measured in events per second…

  • hostking: 1666.66
  • cloudafrica: 5520.08
  • digitalocean: 4096.37
  • Raspberry Pi: 2977.10
  • Desktop PC: 2039.73

50000 events

Time to do 50000 events (fastest of 4 or 2 threads)
Running sysbench --events=50000 --threads=2 --time=0 cpu run measured in seconds

  • hostking: 31.0833 s (2 threads)
  • cloudafrica: 9.0297 s (4 threads)
  • digitalocean: 12.3099s (4 threads)
  • Raspberry Pi: 11.3509 s (4 threads)
  • Desktop PC: 12.5210 s (4 threads)
sysbench-time
Sysbench time – Less is better

FastAPI

A fast api project was created that creates a uuid and returns it as json. If you want to test other scenarios it is important that the test mirrors what your production app will be doing.

WRK 2 workers

wrk -c 4 -d 30s -t 4 http://127.0.0.1:4000/

RPS

  • hostking: 547.98 RPS
  • cloudafrica: 1750 RPS
  • digitalocean: 1010 RPS
  • Raspberry Pi: 290.20 RPS
  • Desktop PC: 1690 RPS

Response time

  • hostking: 1.86ms
  • cloudafrica: 586.32 us
  • digitalocean: 1.02 ms
  • Raspberry Pi: 3.44 ms
  • Desktop PC: 620.74 us (micro seconds)

WRK 4 workers

RPS

  • hostking: 514.88 RPS
  • cloudafrica: 1480 RPS
  • digitalocean: 880 RPS
  • Raspberry Pi: 331.78 RPS
  • Desktop PC: 2120 RPS

Response time

  • hostking: 2.08 ms
  • cloudafrica: 723.45 us (micro seconds)
  • digitalocean: 1.23 ms
  • Raspberry Pi: 3.01 ms
  • Desktop PC: 569.9 us (micro seconds)

2 CPU setups were slower with 4 workers

AB 4 workers (or 2 for 2 cpu machines)

ab -n 10000 -c 100 http://127.0.0.1:4000/
  • hostking: 1709.38 RPS (0.585 ms) – 4 workers
  • cloudafrica: 5334.08 RPS (0.187 ms) – 2 workers
  • digitalocean: 3418.71 RPS (0.293 ms) – 4 workers
  • raspberry pi: 1225.09 RPS (0.816 ms)
  • Desktop PC: 7710.77 RPS (0.130 ms)
Response time
Response time – less is better
requests-per-second
Requests Per Second – more is better

WordPress Performance Difference

Two of the same wordpress instances were created – both with mysql, nginx and php. The only difference was the old vm (with better CPUs) was running php7.4 and the new vm (with worse CPUs) was running php8.1.

Load was added 1 user per second until 200 users were using the site.

cloud-africa-vm-performance
PHP7.4 Cloudafrica 2 CPU VM
old-site-locust-performance
PHP8.1 Hostking 2 CPU VM

Average response time for the old site was 559 ms at 37.5 RPS. The new site averaged 4337 ms at 18 RPS. Median response time broke above 1 second at 50 RPS on the old site. On the new site at 20 RPS the 1 second median barrier was broken.

Conclusion

Not all CPUs are the same. Number of cores per CPU matters. The provider also matters. For CPU intensive workloads and where response time is paramount – cloudafrica provides the best hosted solution.

On average Hostking performance for websites under load is 4 times slower than cloudafrica.

Your own home hardware may provide better results though.