Strict server-side processing (without interacting with a web browser): is Java or PHP better for this scenario?

Here's the situation:

I currently have a web application that uses PHP to work with HTML / CSS / JS, and this is related to the MySQL database. Totally vanilla and plain. PHP is a mixture of presentation logic (HTML generation, etc.) and business logic (the application makes extensive use of Ajax for data requests or tells the server to make changes to something).

As part of the redesign of this system, I remove all presentation logic from PHP. Instead, I will use Ext JS 4 (a javascript-based toolbox / application for creating windows) connected to a web socket gateway (a COMET / AJAX replacement that allows bi-directional communication) on the server. Let the wave of magic wand for a minute and forget about how Ext JS 4 is delivered to the browser and how it talks to the web socket gateway.

What we ended up with is a web socket gateway (written in Java and constantly listening on a specific port for web socket connections) and some business logic / database interactions currently written in PHP.

At this moment, I see one of two options:

  • Maintain the business logic / database interaction in PHP and execute it by calling either PHP from the command line or using PHP / Apache to listen on another port only for communication with a web socket gateway.

  • Write a new Java or C ++ application that will be persistent and listened on on a specific port to communicate with the web socket gateway. The business logic / database integration is rewritten into Java or C ++ code and is part of this application.

Would rewriting in Java or C ++ work better than repeating PHP over and over? (The PHP code is fairly cleanly written: object-oriented using packages such as CodeIgniter and Doctrine).

Will the performance benefits affect the re-creation of the entire business logic? Obviously depends on many factors, such as the amount of code, but what is your gut feeling?

In case this may affect your thinking / feedback, you should be aware that the Kaazing Web Socket Gateway supports JMS, Stomp, AMQP, XMPP, or something that you create yourself.

Let me know if there is any other information I can provide to help you with your answers.

Thanks!

+4
source share
3 answers

I know that many of the solutions that I mention here are "ugly", but you sound like a person who wants to get results and refactoring, so I hope that everything is in order.

Do it in a simple way (PHP, if I understood correctly). Then do a realistic stress test. Since you are creating PHP calls, just create a realistic sequence (log in, change it, do it, log out) and run as many as you think are realistic. 100? 10000? It depends on how much you expect this thing to be and is still being reformed.

This step is easier than it sounds. Do not think that the "ultimate test environment", think that 20 lines of python script start as many threads as you want to execute several lines that will support your application. If you need more than 40 minutes, stop and simplify. The hour you spend will be worth it.

If the processor reaches 100 or you are running out of resources, it may be time to rewrite, or you might guess what to take the longest and write it to C. If you use C / C ++ and you are not 100% comfort with it, avoid major rewriting, as it is a dangerous language with many possibilities for introducing errors. Perhaps even call the compiled code from PHP that you have if it suits your application .

I wrote server-side C code with server-side code once. This is not the right tool for the job. PHP may be hacky, but it does its job quickly. I would avoid optimization if / until it is needed.

Good luck, do not forget to tell us how this happens!

Edit: If you are going to use a mixed language solution, be sure to clear it after! Standardize what you do quickly and what you do in PHP, do it in a common format, maybe write a short readme. Again, these fifteen minutes will save you, or the next person, a few days and a lot of hair.

+2
source

Writing in a compiled language (Java or C ++ in your examples) will almost certainly give better performance than an interpreted language such as PHP. Performance would almost certainly not outweigh rewriting the entire code.

+2
source
  • If your business logic has high processing costs, Java or C ++ will give you much better performance.

    If you simply retrieve some results from the database, do not expect big performance gains.

  • I would do some prototyping / testing to determine the performance bottleneck.

  • I find PHP to be too slow to handle huge datasets if you have many 100,000 objects for analyzing C ++ rocks and the benefits of Java from the HotSpot JIT performance optimizer.

    The HotSpot effect is very specific for cracking numbers in Java. You really see the JRE pushing the accelerator, eliminating the detected bottlenecks. In some rare cases, the optimized Java technology HotSpot JIT can be even faster than C.

    In some also very rare cases where HotSpot voodoo performance can make your code slower!

  • Have you ever thought about turning a PHP application into a faster Java or C ++ application?

    Perhaps the HipHop php2cpp compiler is all you need: https://github.com/facebook/hiphop-php/wiki/

    Quercus is a php4java runtime that can help you switch to Java faster. http://quercus.caucho.com/

  • Last year, Joshua Bloch talked about Performance Concern. http://www.wiki.jvmlangsummit.com/images/1/1d/PerformanceAnxiety2010.pdf

    http://parleys.com/#st=5&id=2103 (32min video)

+1
source

All Articles