views:

114

answers:

3

Whats a good server side language for doing some pretty cpu and memory intensive things that plays well with php and mysql. Currently, I have a php script which runs some calculations based on a large subset of a fairly large database and than updates that database based on those calculations (1.5millions rows). The current implementation is very slow, taking 1-2 hours depending on other activities on the server. I was hoping to improve this and was wondering what peoples opinions are on a good language for this type of task?

+2  A: 

The language isn't the issue, your issue is probably where you are doing these calculations. Sounds like you may be better off writing this in SQL, if possible. Is it? What are you doing?

Noon Silk
Yes, it should be possible. Do you think that would produce the best results?
bobbyb
Most definitely. It'll mean that it's executing right on your server, and the data won't need to be transferred over to PHP/Whatever first.
Noon Silk
+3  A: 

Where is the bottleneck? Run some real profiling, and see what exactly is causing the problem. Is it the DB I/O? Is it the cpu? Is the algorithm inefficient? Are you calling slow library methods in a tight inner loop? Could precalculation be used.

You're pretty much asking what vehicle you need to get from point A to point B, and you've offered a truck, car, bicycle, airplane, jet, and helicopter. The answer won't make sense without more context.

Stefan Kendall
Can you please suggest any good tools for profiling?
bobbyb
http://www.linuxjournal.com/article/7213May or may not be useful. This looks like the cprofile module for python, which I found quite handy.
Stefan Kendall
A: 

I suspect your bottleneck is not the computation. It definitely takes several hours to just update a few million records.

If that's the case, you can write a customized function in c/c++ for MySQL and execute the function in stored procedure.

We do this in our database to re-encrypt some sensitive fields during key-rotation. It shrunk key-rotation time from days to hours. However, it's a pain to maintain your own copy of MySQL. We have been looking for alternatives but nothing is close to the performance of this approach.

ZZ Coder