June 22nd, 2009, 03:10 PM
Best Language for Fast Database Interaction
I currently have a project I have just finished coding in PHP. It does everything it is supposed to do, however it is far too slow. I plan on having one run through of the script read/write over 1,000,000 different values from/into a database (currently MySQL). However, PHP/MySQL is far too slow with this... it takes way to long simply to do 10,000 read/writes. Besides reading databases, the program only uses loops, basic variable operations, and randomly generating numbers.
So I am wondering what is the best programming language/database combination is for reading/writing into a database at peak speed/efficiency.
June 22nd, 2009, 06:06 PM
Reading and writing 1 million average sized records is going to take a pretty good amount of time regardless of what language and database you do it with. Rather than rewriting your script, you're probably better of trying to find some way to not have to read and write so many records at once. Perhaps better caching of some type? It's hard to say without actually knowing what you're doing.
It's also hard to say whether the time you're experiencing is unreasonable since we don't know what type of records you're updating or what your code looks like.
June 22nd, 2009, 07:02 PM
The time it is taking is reasonable, however I know that since PHP is an interpreted language it can be done faster.
I am building a neural network, so the program basically runs by reading/writing hundreds of thousands of database values before giving an output. I understand there are hardware computational limits, and I understand that you can try to make your code more efficient. I am wondering what programming language would be best for this program to run in, and what database would be the best to store the neural network.
June 23rd, 2009, 11:27 AM
PHP/MySQL in my opinion is a good combination for web development. You might need to optimize your code and database design.
I can't think of a faster combination.
P.S.: Good luck using Java..
June 23rd, 2009, 12:26 PM
One thing that makes a huge difference is where the database is vs where the application is. If it's all on the same server then you're not going to get much faster, but otherwise your network comes into play. I work in san francisco and having to query database servers in minneapolis and phoenix. So sometimes I'll commandeer another server in one of these locations to run whatever job I need run because though they might not even be in the same building, running a job in the same city at least sure does help performance :-) This probably doesn't apply here though so I'm ranting needlessly.
Optimize your database and make sure it's properly indexed and you don't have a lot of needlessly large varchars you don't really need and such. You might want to take your design over the the mysql forum and ask there if you could make your design more efficient. This will probably be your best immediate bet to gain efficiency.
“Today you are You, that is truer than true. There is no one alive who is Youer than You.” - Dr. Seuss
June 23rd, 2009, 08:09 PM
You posted in the scripts forum, pretty much all of the languages discussed here are interpreted
Anyway, yes you are correct that an interpreted language is much slower than a compiled language. The fastest reasonable option is going to be C/C++. Java would be faster than PHP too, but not as fast as C/C++. Both of those languages are compiled languages, it is unlikely that you could find another interpreted/scripting language that is considerably faster than PHP.
In this case your issue is almost certainly not the programming language but the database itself.
Your best bet is to switch over to C/C++, get a ton of RAM, load everything in the database into memory, and then use the copy stored in memory to perform your processing.
June 24th, 2009, 12:12 AM
Since the script itself is very small it makes the most sense for the script to be on the same server as the database, so I won't run into any problems with distance.
Would writing an extension for PHP in C/C++ be the optimal way to do this?
At the time I wrote the code (it seemed like the most effecient way at the time) wrote the code so that it would always store the database information into an array before actually doing any calculations with it.
Also for a server, would you recommend an 8 Core server with 8GB of RAM or a 4 Core server with 12GB of RAM? My budget allows me to basically chose one or the other. Although the database will be 1,000,000+ rows it is only 1-2GB in size.