Background:
Dedicated Server on Apache / PHP 5.x / MySql 4.x
What I am doing:
I need some suggestions on the best way to handle the following situation:
My application takes input from a XLS and imports the data into a MySQL database. When the import is done, each record has a lot of processing happen on it, typically 30-60 seconds worth. Most of that time is spent waiting for waiting for CURL requests from other services/servers.
It works fine, except when I get a lot of records...this process can take forever because each record is processed in order. Several hundred records
can take hours. However, the server is basically idle and waiting so I wanted a way to do a bunch of these in parallel.
So I set up a bunch of batch control processes and tables so the background procesess (batch.php) can run in parallel and not collide with records from the other processes. I can kick off a handful of these processes and everything works great.
The batch.php does all the work to get the next record, process it. It then looks for a "kill signal" from the database...if it sees it...it stops. If not, it grabs the next record. If there is no next record, it also stops.
So basically it runs until it runs out of records to work on.
The problem:
The problem however is when I kick off a lot of these processes (10-30). While I am in the process of starting the other batches, the server "hangs" for a few seconds while each process starts and the processes that were already running see the server stop and they all stop as well.
I'm kicking off the processes in Javascript with a button on a page "Add 30 processes". That button will loop 30 times...each time it calls a
XMLHttpRequest to "batch.php". This call essentially starts a instance of the batch program on the server in the background.
What I think is happening:
I think when I kick off this many processes so quickly the server chokes trying to catch up...it's like having 30+ concurrent users (plus whomever else is using the server).
What I think is needed:
I would like to find a way for a PHP app (controller.php) be able to kick off "x" number of batch processes (batch.php) in parallel similar to how the javascript currently does. This way, I can have the "controller.php" look at the server and pace the new processes so the problem doesn't happen.
Thoughts?