Drupal/php vs Java/JSP

Events happening in the community are now at Drupal community events on www.drupal.org.
atisa's picture

I am working on developing a website which includes lots of calculators (users of the website will fill out the form and my website will do some calculations and will present the numeric result and some diagrams). Some of these calculators require relatively intense computations (e.g., integration). I am considering two options:
1. Using drupal/php
2. Using java servlets
My preference is working with Drupal; however, my concern is that php might not be as efficient as java Servlets for computational purposes.

I would appreciate any suggestions or comments.

Comments

Drupal & Speed

dpatte's picture

On my own website at relativedata.com, I am using Drupal to talk to C++ cgi/fastcgi for speed. That's also an option.

If it's that compute-intensive, why not code it in C?

MBR's picture

The fact that Java doesn't have to parse the source code at runtime should make Java a little faster than PHP, but I'm not sure just how much faster. But keep in mind that although Java is compiled, the resulting JVM code still has to be interpreted.

If what you're doing is as compute-intensive as you say, and if you have a sufficient level of administrative access to the server, use Drupal and PHP but write the computation-intensive part in C. Machine code compiled from C is much more efficient than interpreted JVM code.

There are a few ways I can think of to invoke the C code from PHP:

  1. The most efficient is to write the code as a PHP extension. If you have sufficient privileges on the server to install an extension to PHP, this will run the fastest. I wrote a PHP extension a couple of years ago, and the part that took the longest was finding the right book to learn PHP's internal API. Once I had the book, the coding was pretty easy. The book you want is "Extending and Embedding PHP" by Sara Golemon (http://www.amazon.com/Extending-Embedding-PHP-Sara-Golemon/dp/067232704X...). You don't need to read the whole book. Just learn enough about the symbol table layout and the API so you can pass the datatypes you care about back and forth between PHP and C.

  2. If you don't have sufficient privileges on the server to install a PHP extension but you can install a Unix daemon, use straight socket calls. PHP's fsockopen() makes the client side of this pretty easy. Doing the server side in C is a little messier, but you can find a good example at http://en.wikipedia.org/wiki/Berkeley_sockets#Server. Rather than a direct call to the C code like in #1, at runtime this will do reads and writes via a network connection. So it will be slower than #1, but not that much slower because the client and the server are both on the same host. Thus no actual network transmission takes place. The I/O just involves copying data back and forth between the buffers in application space and buffers in the kernel.

  3. If you can't do either of the above, write your C-code as a CGI program. This has the downside that Apache has to do a fork() and exec() of your CGI program for every request, which is more costly in compute time than the other approaches. There's a Perl example at http://en.wikipedia.org/wiki/Common_Gateway_Interface. You'll do the equivalent in C. Your args will come in via the environment variable QUERY_STRING, and your results will be sent back by writing to STDOUT.

If you have further questions, send me a message via my drupal.org Contact page.

Mark Rosenthal (MBR)

Thanks

atisa's picture

Thanks for your suggestions. Really helpful links and comments!

Boston

Group categories

More Specifically

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: