Why is my python script 10x slower on a DO Droplet than running on my computer?

I am a Python developer, hosting a Flask application on a DO droplet. I am new to cloud hosting so I am learning as I go and have a question / looking for direction.

I have a simple python script that runs some calculations, and updates an SQLite database. Locally on my macbook it takes ~23 seconds. Running it on my DO droplet, it takes ~222 seconds.

I recently migrated my code to a new DO droplet, I don’t remember the previous droplet being this slow.

This droplet is I believe a shared CPU, Regular 80 gb SSD hdd, 4 gb ram, 2 cpus. It’s running Ubuntu 22.04 and Python 3.10.

I can’t find what the previous droplet was, but it was created when the cheapest option was $5/month for 1 gb / 1 CPU.

What is likely causing this script to be this much slower on my droplet? I know the CPU is not running at 100%.

What can I do to speed it up, at least to the same speed as my desktop? I don’t want to start blindly resizing my droplet.

Thank you

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Site Moderator
Site Moderator badge
January 9, 2023

Hello @rbourne

I would assume that the part of the script which is taking more time now to complete will be the SQLite database query. Are you doing a remote query or is the database hosted locally on the droplet?

I’ll personally have a look at executing the query via the command line to check if this is the bit that takes more time to complete and then check if the process can be optimized.


Site Moderator
Site Moderator badge
January 9, 2023

Hi @rbourne,

The script will be slower only if your Droplet is under heavy load when running it or if it’s creating a heavy load. You mentioned the CPU was not at 100% but what about the RAM?

Additionally, try to debug your script. Try to find out on which line it’s slowing down, which command it’s trying to execute for so long, and then take it from there. That would be my approach.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel