I have an application that I can run fine on my own computer (i5 @ 3.00GHz, nothing extraordinary), yet when I run the exact same code on a computing optimized instance (c5.xlarge, 3.4 GHz), it runs at around 10% of the speed.
I know for sure the issue is not the memory as the application takes a few hundreds MB when running, and it’s not the I/O operations as it writes / reads to the disk for a few seconds max (the application takes a few hours to run). When I look at the CPU usage, it’s at 25% due to the application being single threaded, but it’s the same on my computer so that’s not the problem.
I really have no idea how to improve the performances, or even where to look for anymore since cloudwatch has been no use.
The libraries used are the same / same versions installed.
If anyone has clues on where to look, I’d gladly take any advice.
c instance types are compute optimized, m instance types are general purpose. Without knowing the details of your application it’s hard to say why. My guess is that you were constrained by memory, not compute.
If you’re running a newer i5 a lot of it can have to do with 1. Single thread turbo boosting and 2. IPC instructions per clock. Couple that with faster I/O and probably much faster RAM speeds and I can see a massive performance difference.
What you really want to do is see if you can take more advantage of the extra CPU you’re not using in the instance with multi threading.
One quick thing you can do is test flipping it back to a C5 and re-testing your performance. It’s possible there’s a bad host in the EC2 fleet that’s degraded just enough to impact you but not enough to trip monitoring on their side. If a new C5 is equally impacted then it’s likely a legit issue with resource contention and resource differences between the C and M platform. If the new C5 works just fine then I would lean towards a bad host that (if you have Support) would be worth a ticket to let Premium Support know about.
Does the application has any dependencies that needs to be resolved over the network? Does the application waits for IO somehow? (I know I am overcomplicating with this point :))
I think for properly benchmarking, you could try use same AMI you used in AWS locally by creating a VM (I believe it could be some recent version of Amazon Linux 2). The platform may have its toll. The main reason is, if you are going to deploy the application in EC2 for using it at scale, it is better to replicate it locally with same OS image.
Do you see anything significant in application logs to understand which piece of code is creating a bottleneck?
As u/forforf mentioned, did you check if your application is memory constrained? Like you compared the CPU utilization, did you compare memory? Of course this would be quire easier if you have a separate VM running (as mentioned in #2).
Actually I ran a few benchmarks and ended up finding the root of the problem which is actually not solved, it only seemed to be.
I know the one function taking all the time is numpy.searchsorted even though it’s used on a int64-only array, but it only starts slowing down after a few seconds. The first ones run just like my computer or even faster, then it’s like 100x slower and never goes back to normal. Pretty weird behavior
Thanks a lot for being that interested in the subject!
There are 0 network calls after the initialization and the initialization runs smoothly
I didn’t know about that I’ll definitely check it out
After running a few benchmarks and some profiling, I found that when the application bottlenecks on one function, numpy.searchsorted, but ONLY after some time has passed. However when I check the cpu and memory usage, they are still around the same values (cpu: 99%, memory: 60%). Since a numpy function was the root of the problem, I thought it could be due to a GPU problem, but after changing for a G3s instance (with GPU) the problem was not solved.