Forums

Performance / multiprocessing

I'm doing some (heavy) scientific calculations on my brand new account. On my first steps I tried it pure single-core, but it ran even slower than on my shabby core i5. Multicore was the same. Both not being in the tarpit. What's the best way, to achieve more performance?

Within Python, I'm using a pool of workers from the multiprocessing package. os.cpu_count() shows 2 cores. Is it possible, to use more? Or how do I handle it the best? As I'm new to cloud computing, there are so many questions ;)

In general, once you're using all the cores on a machine, the best way to achieve more performance is to write better algorithms. On PythonAnywhere, that could mean caching results, not writing to disk as much, reducing the amount of data you're requesting from a database (network latency can really hurt performance) etc.

I would suggest profiling your code to see where it's spending most of its time and trying to see why that piece of code is a bottleneck.

As an example of this, I was trying to make a piece of code that used pandas to aggregate some data from a database and simply changing the way that I accessed and updated values in the pandas dataframe dropped the slowest part of the code from 200s to under 20s.

If you are doing something that can be parallelised, I know the PA guys have done custom plans for people with them having access to hundred (or even thousands) of cores.

@glenn, thank for your answer! so far, my algos are optimized some times and I'm working on it on and on. The data itself is already completely cached in RAM (about 500MB). Am I right, that we users get exactly one core of those Xeon processors and if python says, there are two, it means the one + threading? But although, my code isn't written best (I'm totally aware of this ;)), shouldn't that one Xeon core be faster than one of my i5 cores? By the way, how many RAM are we allowed to consume, before it gets swapped or so?

@rcs1000 sounds perfect, but how to get those plans? Haven't seen any options for that.

The cores on PythonAnywhere are shared with other users. As is the memory: 500MB is likely to be swapped in and out of memory to the disk.

If you're interested in a custom plan, send an email to support asking about dedicated servers. Be aware that it is significantly more expensive, though.