views:

254

answers:

9

According to this page,it seems that Perl,PHP,Python is 50 times slower than C/C++/Java.

Thus,I think Perl,PHP,Python could not handle critical application(such as >100 million user,>xx million request every second) well.But exceptions are exist,e.g. facebook(it is said facebook is written with PHP entirely),wikipeida.Moreover,I heard google use Python extensively.

So why?Is it the faster hardware fill the big speed gap between C/C++/Java and Perl/PHP/Python?

thanks.

A: 

there is no JIT compiler in php which Compile the code into machine code

Another big reason is PHP's dynamic typing. A dynamically typed language is always going to be slower..

click below and read more

What makes PHP slower than Java or C#?

peacmaker
why the down vote ?!!
peacmaker
When downvoting, please add a comment explaining why you downvoted, so the user that answered may have a chance of correcting oneself, and improving in the future.
Ehrann Mehdan
The question is not about why one language is slower than another, the question is which is better for web development, so its answering the wrong question. Furthermore, the OP is confused that raw performance makes for a better language and this answer just fuels that.
Schwern
i only recommended an article that may help in better understand why php is slow than some of other language.
peacmaker
+4  A: 

The page you are linking only tells half the truth. Of course native languages are faster than dynamic ones, but this is critical to applications with high computing requirements. For most web applications this is not so important. A web request is usually served fast. It is more important to have an efficient framework, that manages resources properly and starts new threads to serve requests quickly. Also the timing behaviour is not the only critical aspect. Reliable and error-free applications are probably better achieved with dynamic languages.

And no, faster hardware isn't a solution. In fact Google is famous for using a cluster of inexpensive machines.

kgiannakakis
Faster hardware is A solution; Google just decided it was more cost-effective to use commodity hardware with wide heat tolerances.
Robert Grant
Faster hardware is a solution for making a properly designed application run faster and being able to serve more users. It isn't a solution for making a poorly designed application work better.
kgiannakakis
kgiannakakis + Robert Grant ergo, Google is a poorly designed application
Pete Kirkham
"For most web applications this is not so important" - Because native languages are used for the applications glued together by the interpreted languages.
igouy
@kgiannakakis: Faster hardware is used extremely often as a way to make poorly designed applications run faster. Hardware costs money, faster hardware costs more, but the cost is decreasing. Design costs money, proper design costs more, and the cost isn't decreasing.
David Thornley
+3  A: 

(such as >100 million user,>xx million request every second)

To achieve that sort of performance, you are going to HAVE to design and implement the web site / application as a scalable multi-tier system with replication across (probably) all tiers. At this point, the fact that one programming language is faster / slower than another probably only affects the number of machines you need in your processor farm. The design of the system architecture is far more significant.

Stephen C
A: 

Google is using Python for GAE and Windows Azure is providing PHP. The LAMP architecture is a great for application scalabilty.

I also think that the programming language is not that important regarding performance. The most important thing is to look at the architecture of your app.

I hope it helps

luc
A: 

To serve a web page, you need to:

  1. Receive and parse the request.
  2. Decide what you wish to do with the request.
  3. Read/write persistent data (database, cache, file system)
  4. Output HTML data.

The "speed" of the server side language only applies to steps two and four. Given that most scripts strive to keep step 2 as short as possible, and that most web languages (including PHP) optimize step 4 as much as they can, in any serious web site most of the request processing time will be spent in step 3.

And the time spent on step 3 is independent of the server-side language you use ... unless you implement your own database and distributed cache.

Victor Nicollet
+6  A: 

Computational code is the least of my concerns in most heavy usage web applications.

The bottle necks in a typical high availablility web application are (not nessecarility in this order, but most likely):

  1. Database (IO and CPU)
  2. File IO
  3. Network Bandwidth
  4. Memory on the Application Server
  5. Your Java / C++ / PHP / Python code

Your main concerns to make your application scalable are:

  1. Reduce access to the database (caching, with clustering in mind, smart quering)
  2. Distribute your application (clustering)
  3. Eliminate useless synchronization locks between threads (see commons-pool 1.3)
  4. Create the correct DB indexes, data model, and replication to support many users
  5. Reduce the size of your responses, using incremental updates (AJAX)

Only after all of the above are implemented, optimize your code

Please feel free to add more to the list if I missed something

Ehrann Mehdan
+2  A: 

C is easily the fastest language out there. Its so fast we write other languages in it. Nobody seriously writes web sites in C. Why? Its very easy to screw up in C in ways that are very difficult to detect and it does almost nothing to help you. In short, it eats programmers and generates bugs.

Building a robust, fast application is not about picking the fastest langauge, its about A) maintainability and B) scalability.

Maintainability means it doesn't have a lot of bugs. It means you can quickly add new features and modify existing ones. You want a language that does as much of the work as possible for you and doesn't get in the way. This is why things like Perl, Python, PHP and Ruby are so popular. They were all written with the programmer's convenience in mind over raw performance or tidiness. C was written for raw performance. Java was written for conceptual tidiness.

Scalability means you can go from 10 users to 10,000 users without rewriting the whole thing. That used to mean you wrote the tightest code you can manage, but highly optimized code is usually hard to maintain code. It usually means doing things for the benefit of the computer, not the human and the business. That sacrifices maintainability and you have to tell your boss its going to take 3 months to add a new feature.

Scalability these days is mostly achieved by throwing hardware at it and parallelizing. How many processes and processors and machines can you farm your work out to? If you can achieve that, you can just fire up another cheap cloud computer as you need it. Of course you're going to want to optimize some, but at this scale you get so much more out of implementing a better algorithm than tightening up your code.

For example, I took a sluggish PHP app that was struggling to handle 50 users at a time, switched from Apache with mod_php to lighttpd with load balanced, remote FastCGI processes allowing parallelization with a minimum of code change. Some basic profiling revealed that the PHP framework they used to prototype was dog slow, so it was stripped out. Profiling also suggested a few indexes to make the database queries run faster. End result was a system that could handle thousands of users and more capacity could be added as needed while leaving most of the code implementing the business logic untouched. Took a few weeks, and I don't really know PHP well.

It may be beneficial to reimplement small, sharp pieces in a very fast language, but usually that's already been done for you in the form of an optimized library or tool. For example, your web server. For the complexity and ever-changing needs of business logic the important thing is ease of maintenance and how good your programmers are.

You will find that most of the web is written in PHP, Perl and Python because they are easy to write in, with small, sharp bits written in things like C, Java and exotics like Scala (for example, Twitter). Wikia, for example, is a modified Mediawiki which is written in PHP but it is performant (amongst other reasons) by doing a heroic amount of caching.

Schwern
"Its so fast we write other languages in it" - that's much more to do with the expectation that whatever hardware exists some C compiler will support that hardware.
igouy
A: 

For php, there are lot of things you can do to increase performance. For example

  • Php Accelerator
  • Caching Queries
  • Optimize Queries
  • Using a profiler to find slower parts and optimize

These things would certainly help reduce the gap between lower level languages. So to answer your question there are other things you can do inside the code to optimize it and make it run faster

SeanDowney
A: 

I agree with luc. Its the architecture that really matter and not the programming language.