Underperforming CPU

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.

Have you tried a different instance type? If not, maybe try an m5.xlarge and see if there’s any improvement.

Thanks for this, I’m gonna try it right now

What kind of application is it? A linux executable? Did you build it separately on the AWS instance or just copied the binary?

It could be considered as a python script, no build is required so I just git cloned and ran it

It appears you’re my savior, it’s working, but now I don’t know why. Anyway, thanks for this tip, I had tried many instances but not the m5 ones

Apparently changing for a m5 instance solved it, but I’m confused because the monitoring showed like 10% memory usage

Weird. I would be super interested in finding out why this happened. But it could take a while.

Yeah me too because it could happen again anytime

But I looked for reasons all afternoon, I can’t believe the solution was that simple xD

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.

I see it’s already resolved. For future reference, if such a thing would happen to me, here’s a few ideas to try:

  • Try the c6i instance types, which are newer and faster
  • Try create a flamegraph to pinpoint where your app is spending its time (e.g. rbspy/py-spy/etc.)
  • Check if you are excessively checking the current time
  • Check if you’re not using /dev/random excessively
  • Try a upgrading the kernel
  • Make sure you’re not doing any excessive DNS queries
  • Run a strace and see anything weird

Few questions:

  1. 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 :))
  2. 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.
  3. Do you see anything significant in application logs to understand which piece of code is creating a bottleneck?
  4. 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

You’ll probably get a better answer if you post code to reproduce the issue in /r/numpy

Here’s a sneak peek of /r/Numpy using the top posts of the year!

#1: How to tell when numpy function is optimized via parallelization and when mpi4py is needed?
#2: Are triangular matrices more efficient in Numpy?
#3: NumPy Illustrated: The Visual Guide to NumPy | 0 comments


^^I’m ^^a ^^bot, ^^beep ^^boop ^^| ^^Downvote ^^to ^^remove ^^| ^[1](https://www.reddit.com/message/compose/?to=sneakpeekbot) ^^| ^[2](https://np.reddit.com/r/sneakpeekbot/) ^^| ^[3](https://np.reddit.com/r/sneakpeekbot/comments/o8wk1r/blacklist_ix/) ^^| ^[4](https://github.com/ghnr/sneakpeekbot)


  1. Contact ↩︎

  2. Info ↩︎

  3. Opt-out ↩︎

  4. Source ↩︎

Alright thank you :slight_smile:

Thanks a lot for being that interested in the subject!

  1. There are 0 network calls after the initialization and the initialization runs smoothly

  2. I didn’t know about that I’ll definitely check it out

  3. 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.