-2

I'm running a $5/mo server on DigitalOcean - 1 GB RAM, 1 VCPU.

I have a script which contains a for loop and will take some time to run (I have disabled timeouts).

If I increase the specs of the server (e.g. to 16GB RAM, 8 VCPUs), will that automatically speed up the task?

Or would I have to manually implement multi-threading or something?

Or perhaps split the task into chunks and make multiple HTTP requests

This is with NGINX

1
  • 1
    Please think about what you're asking before blindly posting "Will increasing CPU speed" && "8 VCPUs" If I asked that in car terms you're saying "Will the ability to rev the engine higher give me more gears" CPU speed measured in GHz, not in cores The other answer (Why I'm giving you a down vote) is "Have you tried it?"
    – Timothy c
    Apr 28, 2021 at 20:53

2 Answers 2

0

PHP is single-threaded. More CPUs will not help.

Multithreaded PHP is something that has been promised for twenty years now, and has not gained significant traction. I'd expect several hard-to-debug problems if you try.

Your best bet would be to run multiple scripts with part of the problem in parallel -- if HTTP is your only interface to that, concurrent requests is the way to go. Then the number of CPUs allocated to your vServer becomes relevant. Keep in mind that the machine is likely oversubscribed, so CPUs are shared with other customers, the allocation only affects how many tasks it will even try to schedule in parallel.

0

I have a script which contains a for loop and will take some time to run ... If I increase the specs of the server ... will that automatically speed up the task?

Not "automatically", no.
It depends entirely on what you're doing inside that loop.

If you're performing some intense, numerical computation then sure; giving it more CPU power probably will help.
If you're reading the entire contents of the Encyclopaedia Britannica, page by page, across the Internet the not so much.

First find out what you need to do, then find out how to do it well.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .