开发者

For high scalability & performance needs, is it preferable to have C++ or Java implementation at the backend of a PHP application?

For high scalability & performance needs for a social portal, is it advisa开发者_Python百科ble to have C++ or Java implementation at the backend of an PHP application ?

What are the benefits & trade-offs of the same ?


In raw performance terms, C++ will get you a fair bit further than Java or PHP, and slightly further than C#. By this I mean that if you implement the same algorithm in these different languages you are most likely to see the best performance from C++ (although it will depend exactly on what you're doing and how you do it - a different language on its own is not a magic bullet; you need to learn how to make the best use of that language, which can take years).

As @spender has said, using well thought out algorithms and architecture will usually give a greater gain in performance and a much greater gain in scalability than simply switching to a different language might achieve. Performance is fundamentally about being efficient (minimising your usage of resources like bandwidth, memory, disk and CPU) and scalabilty is primarily about making things work well in parallel (minimising contention for resources like data, bandwidth, memory and CPU, and minimising the need for different parts of your system to communicate with each other)

As @Kugel said, if you have a truly scalable architecture then you can to some extent just throw more hardware at the problem, which might initially be a cheaper approach than rewriting everything in a different language. However, if your site is successful, making your code as efficient as possible will reduce your hardware and running costs.

Another consideration may be development/maintainability related - if you are an expert in PHP and a newbie at C++, you may well squeeze more out of PHP than you can out of C++. You have to consider the whole picture and work out what is the most "commercially viable" solution, not just what is the theoretically highest performing one. Or you may find that your "thrown together and works surprisingly well" PHP solution is up and running in a week while your highly optimised C++ never quite gets finished.


You aren't writing the next facebook. Write it in PHP (or whatever language you're most comfortable with) for now. If you're lucky enough to grow large enough to the point where php can't handle the load then you can redesign your site. Unless you're running one of the top 100 sites it the world you're just engaged in premature optimisation.


First of all PHP is already a backend. PHP itself is implemented in C or C++.

For scalability language doesn't matter, because scalability is about parallel handling of multiple requests.

For performance as in "get a single request processed as soon as possible", language usually matters that's why Facebook wrote PHP to C++ compiler.


It depends on your definition of "high" and dozens of other factors. Usually performance should be just "enough". From my experience, trying to write the fastest possible implementation from start can backfire badly. As to language choice IMO it depends more on people writing the code and their experience with the problem domain.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜