Slashdot Mirror


The Environmental Impact of PHP Compared To C++ On Facebook

Kensai7 writes "Recently, Facebook provided us with some information on their server park. They use about 30,000 servers, and not surprisingly, most of them are running PHP code to generate pages full of social info for their users. As they only say that 'the bulk' is running PHP, let's assume this to be 25,000 of the 30,000. If C++ would have been used instead of PHP, then 22,500 servers could be powered down (assuming a conservative ratio of 10 for the efficiency of C++ versus PHP code), or a reduction of 49,000 tons of CO2 per year. Of course, it is a bit unfair to isolate Facebook here. Their servers are only a tiny fraction of computers deployed world-wide that are interpreting PHP code."

752 comments

  1. php is bad for the environment by Anonymous Coward · · Score: 0

    All the more reason to use perl! notcop

    1. Re:php is bad for the environment by Pieroxy · · Score: 5, Insightful

      Seriously, is somebody taking seriously the 1 to 10 ratio of the story?

      I mean, maybe raw execution of pure code is going 10 times slower in PHP than C++ (ouch, I didn't know that) but even then, it's far from representing the same ratio when talking about a number of servers. You have to take into account all other parameters (disk access, network, IO, etc... Those aren't 10 times as slow in PHP one would guess).

      I would be astonished if this ratio is close to be the truth. Does anyone have any insight/information on this?

    2. Re:php is bad for the environment by tixxit · · Score: 4, Informative

      Exactly. He using stats from benchmark results from pure number-crunching tests. Seriously, here are the tests: pidigits, reverse-complement, regex-dna, k-nucleotide, n-body, fasta, binary-trees, fannkuch, spectral-norm, mandelbrot. Yep. Looks like stuff a web page would do... The biggest bottle neck is probably data access, in which case the language really doesn't make much, if any difference.

    3. Re:php is bad for the environment by Barnett · · Score: 3, Funny

      Seriously, is somebody taking seriously the 1 to 10 ratio of the story?

      Only 1 to10 ?!? I would have thought 1 to 100.

    4. Re:php is bad for the environment by Anonymous Coward · · Score: 0

      The biggest bottle neck is probably data access, in which case the language really doesn't make much, if any difference.

      Not true, e.g. I/O operations in Perl are faster than in PHP.

      P.S. in pure number crunching C++ is thousands of times faster than PHP.

    5. Re:php is bad for the environment by sznupi · · Score: 1

      "if any difference" is going slightly too far probably? There should be some, if only because of lower CPU utilization (plus possibility of using much more efficient, even if slower, CPUs?), and hence somewhat lower power usage (including cooling). However slight. But yeah, certainly nothing close to 10:1.

      --
      One that hath name thou can not otter
    6. Re:php is bad for the environment by fuzzyfuzzyfungus · · Score: 1

      In addition to that, quite dodgey looking, ratio, you have to take into account why PHP was being used.

      Even if the environment were a complete non-issue, nobody would pay substantial amounts of perfectly good money to keep ~20,000 servers humming. This tells us that either A) using PHP is substantially cheaper on the development side than using C++ would be(for this particular application or B) somebody used PHP long ago, because this facebook thing is just a quick hack, right? and now it is cheaper to live with their legacy than to break free of it.

      While servers have a direct environmental impact that is pretty easy to measure(electricity consumption/year * nastiness of local form of electricity production), "development" also has one. The reason that development is expensive is that it involves forking over large sums of money to pay programmers and managers and such. With the occasional exception of that-weird-dude-who-telecommutes-from-his-solar-powered-eco-commune, pretty much every dollar spent on programmers and managers ends up being spent either on A) living a lavishly energy-intensive western lifestyle(if your dev team is local) or B) rapidly and dramatically increasing the already enormous population of the developing world's appetite for energy intensive lifestyles.

      If you want to play the "OMG-environment" game, you can't just focus on the stuff that is trivial to measure and ignore the hard stuff.

    7. Re:php is bad for the environment by maxume · · Score: 1

      It isn't even clear that they measured the trivial stuff, they just took a guess (If Facebook cared to, they could probably come up with a slightly better estimate of their PHP overhead).

      --
      Nerd rage is the funniest rage.
    8. Re:php is bad for the environment by postbigbang · · Score: 3, Interesting

      Some optimized assembler would make a difference (ducks).

      But network latencies, number of sustainable TCPs per session, db latency, weird table lookups (even arp drags a server down when you have 20K+ connects) are all at issue. Add in various dirty caches, file locks/unlocks and other OS machinations, and life can be tough for any app written in anything.

      Then there are the backup servers, the availability servers, the DNS servers, the coffee servers, it just gets bogged down. A 10:1 efficiency claim is probably just language fanboy-ing..... or a consulting job looking for a spot marked X.

      Certainly it's nice to be green... but using better optimization tricks (like GCD) for multi-cores is bound to help.... tickless kernels..... SSDs..... C++ wouldn't be my first pick.

      --
      ---- Teach Peace. It's Cheaper Than War.
    9. Re:php is bad for the environment by Znork · · Score: 5, Insightful

      "development" also has one.

      Not to mention clients. 20K servers is nothing compared to the millions of clients drawing higher power due to running looping flash commercials.

    10. Re:php is bad for the environment by Hurricane78 · · Score: 3, Informative

      From my personal experience: Data-heavy applications run at a complete crawl in PHP. 10 times slower, is, in my opinion, a vast understatement.

      Then again, that’s not the point of PHP. The point is, that in PHP, provided you already know how to program, also get things done more than 10 times faster, than in C++. Because there is a simple function with defaults and automatisms for literally everything.

      Only if those defaults and automatisms are other than what you expect, you will get into big trouble. And because the PHP interpreter is truly a horrible piece of shit (I was able to run totally illegal constructs, with plain text right in the middle of the code, and it ran, doing nothing of what I expected it to do.), that happens quite a lot.
      It’s one reason that drove me to the extreme strictness of Haskell, where you have to get it right upfront, so it doesn’t bite you in the ass later.

      --
      Any sufficiently advanced intelligence is indistinguishable from stupidity.
    11. Re:php is bad for the environment by Bruha · · Score: 5, Funny

      "even arp drags a server down when you have 20K+ connects"

      Are you perhaps a server admin in my company? I swear this is the best excuse for poor performance I've ever heard.

    12. Re:php is bad for the environment by mhelander · · Score: 1

      Agreed, it does seem a bit strange, to say the least.

      A lot of the code for running a web app will not be written in the scripting language for the front end. The database engine, the app server and many libraries will have been implemented using more efficient languages. php scripts are essentially a configuration layer on top of all the more efficient binaries below it.

      So, say for the sake of argument that we converted the php scripts to C. But perhaps we still have a few xml configuration files around. Now someone could look at those and go "OMG they are 100 times slower than C - let's rewrite them in C and throw out 99% of our servers!" ...which would be kind of a stupid argument to push, but it seems to me that's pretty much what they are saying, but with regards to the portions of a system that are php.

    13. Re:php is bad for the environment by shogun · · Score: 4, Insightful

      It probably is a valid excuse if you have 20,000 client machines connecting locally via ethernet from a B class subnet such that the arp tables on the server keep overflowing.

      Of course if you, as a system administrator ever let such an environment be setup you probably are really good at excuses anyway.

    14. Re:php is bad for the environment by RichardJenkins · · Score: 4, Funny

      Don't forget to take account of the energy required to heat the water for the extra coffee it would take to build it in c++. People always forget about the coffee:production ratio.

    15. Re:php is bad for the environment by tomhudson · · Score: 2, Interesting

      The biggest bottle neck is probably data access, in which case the language really doesn't make much, if any difference.

      Wrong - the language makes a huge difference. Try using the c api and CLIENT_MULTI_RESULTS and CLIENT_MULTI_STATEMENTS and concatenating 10,000 queries into one request, then using mysql_next_result() to get the next result set (no, not the next row, the next result set - 0 or more rows).

      One connection. Not 10,000. A BIG difference in execution time. Testing showed that the optimum amount of strcat()ed or fsprintf'd queries was between 10,000 and 20,000 on hardware with limited resources (half a gig of ram, single cpu).

      If each page requires 50 hits on the database, you're going to see a big difference.

      Now imagine this on a machine with much more ram and more than one core.

      More reading: http://dev.mysql.com/doc/refman/5.0/en/mysql-next-result.html

    16. Re:php is bad for the environment by tomhudson · · Score: 1

      Oops - typo: s/fprintf/sprintf/ - sorry for the typo. And no, we never overflowed the buffer - always checked the arguments length before adding more data.

    17. Re:php is bad for the environment by pubwvj · · Score: 1

      For the portion of processing that the interpretation is occupying the 10:1 ration is probably conservative. It may be 400:1. Compile.

    18. Re:php is bad for the environment by Penguinisto · · Score: 1

      Wow - if 20k arp connects are killing your servers, maybe you need to fix that :/

      No, really... you need to fix that. :)

      Now the biggie would be 20k users sending writes to disk - that would drive iowait into the frickin' stratosphere, even if you had the fastest disks alive. THAT is the fastest way to bog a server down.

      I assume that the databases are not on the same servers as the PHP code sitting around, but that doesn't mean that the server load would drop as big as TFS says, since the databases will remain the same size no matter what you use on the front-end.

      (which reminds me - maybe the article author should have compared loads from MySQL to Postgres to Oracle to (*snort*) SQL Server... THAT would have been a real comparison.)

      --
      Quo usque tandem abutere, Nimbus, patientia nostra?
    19. Re:php is bad for the environment by Firehed · · Score: 2, Insightful

      Which would be very relevant if Facebook was doing heavy number-crunching. The only numbers on the site are comment and friend counts, which isn't especially taxing work (especially since it's all de-normalized). The majority of FB is database activity and transforming that into HTML and JSON. If you want to place blame for inefficiency, MySQL would probably be your best bet.

      --
      How are sites slashdotted when nobody reads TFAs?
    20. Re:php is bad for the environment by Anonymous Coward · · Score: 0

      two words: adblock :)

    21. Re:php is bad for the environment by Anonymous Coward · · Score: 0

      even arp drags a server down when you have 20K+ connects

      *cough*BULLSHIT*cough*

      Firstly, ARP replies are cached. Secondly, a request is only made when the cache expires and when sending a packet directly to a neighbour on the same wire. 20k ARP requests means a packet each to 20k neighbours on the same wire / subnet. It has nothing to do with user connections.

      Furthermore, in case somebody decides to press the point, my benchmarks show I can resolve something in the order of 200 million ARP cache hits per second on a single core on decent hardware.

    22. Re:php is bad for the environment by BoxRec · · Score: 1

      I had a number crunching PHP batch program that was taking about 45 minutes to run. After a long and tedious rewrite in C++ the best I could get was about 5 minutes faster (~10% improvement). On line the main performance hit with PHP (relative to C++) is the interpretation which can largely be negated using APC for caching and optimizing the intermediate code. Considering the nature of on line programs I would expect even less that the 10% gain I squeezed from the batch program. Of course it's horses for courses but from my experience I find the 10:1 ratio unrealistic for real world applications..

    23. Re:php is bad for the environment by garnetlion · · Score: 1

      Not to mention clients. 20K servers is nothing compared to the millions of clients who should be running Flashblock.

      FTFY.

    24. Re:php is bad for the environment by whoisisis · · Score: 1

      As a rule of thumb, I've heard compiled languages beat interpreted ones by a factor of 600.
      Some languages, like C# and Java lands in between. They're compiled to some fictional machine
      which is emulated by software. I don't know where they land in this.

      PHP is compiled on the fly, and IIRC you can cache the compiled output on a busy server to save
      quite a bit of time.

    25. Re:php is bad for the environment by postbigbang · · Score: 1

      You took the bait. Now spit it out. ;)

      --
      ---- Teach Peace. It's Cheaper Than War.
    26. Re:php is bad for the environment by Hal_Porter · · Score: 1

      You're a C denier who is killing the planet with your evil lying facts! Off to Kamp Kernighan for you - you'll parse strings with pointers - AS K&R INTENDED - until you crack!

      --
      echo -e 'global _start\n _start:\n mov eax, 2\n int 80h\n jmp _start' > a.asm; nasm a.asm -f elf; ld a.o -o a;
    27. Re:php is bad for the environment by moosesocks · · Score: 1

      The sad thing is that the open-source community hates flash (with *very* good reason), but hasn't brought forth any legitimate alternatives. Moon/silverlight is a legitimately good alternative, but has been bogged down by licensing concerns (the legally-binding promises made by Microsoft don't even appear to have registered on the consciousness of RMS and the like)

      That said, I wonder if some sort of legal class-action can be brought against Adobe for making such a fantastically inefficient piece of software. The effect on power-consumption across an entire enterprise must be quite high.

      --
      -- If you try to fail and succeed, which have you done? - Uli's moose
    28. Re:php is bad for the environment by Anonymous Coward · · Score: 0

      No, it is more than that. Try 10 to 100.

    29. Re:php is bad for the environment by Surt · · Score: 1

      Java and C# can both actually beat compiled languages because they can try multiple compiler strategies at run time and use the winner. Compiled code has to accept the best guess from compile time.

      --
      "Who is the Journal of Quantum Physics going to believe?" --Stephen Hawking
    30. Re:php is bad for the environment by mysidia · · Score: 2, Insightful

      I think it's fair to say that FB servers generate a large amount of database I/O.

      And their PHP code is likely running a lot of graph flow, pattern matching, and other data mining algorithms.

      Including plaintext indexing and search algorithms

      Remember, the whole point of the social network from an advertiser perspective is to select people on the network who are most likely to be interested in certain ads.

      This suggests a lot of elaborate DM on FB's part.

      Just because the intensive computations aren't obvious to the end-user, doesn't necessarily mean there is no heavy numerical computation being done behind the scenes.

    31. Re:php is bad for the environment by Anonymous Coward · · Score: 0

      Not 10x slower, at a minimum it's more like 25-30x slower even with APC. On tight numerical kernels (not what facebook is doing, I know) it's more like 1000 to 1500x slower.

      These interpreted languages are a sin.

    32. Re:php is bad for the environment by mysidia · · Score: 1

      Not if your LAN is correctly configured.

      Ok. 20,000 machines on a Class B subnet is ludicrous.

      With so many, you should divide the LAN and subnet with routers, or if for some ludicrous reason you must keep a class B subnet, then use a LAN divided transparently with routers acting as Proxy ARP servers.

      No excuses.

    33. Re:php is bad for the environment by Tablizer · · Score: 1

      What's a "data-heavy" application? If it's data-heavy, then perhaps one should try farming most of the work off to the database. If you cannot, then perhaps the schemas are poorly designed. (However, it's not always possible to change poor schemas without significant down-time.)

    34. Re:php is bad for the environment by Anonymous Coward · · Score: 0

      Or you've taken over the network from some dipshits who didn't know any better. Oh, and management is made up of a bunch of accountants and marketers who can't tell a keyboard from a monitor, and they won't give you the funding necessary to fix the fucked up mess you're dealing with.

    35. Re:php is bad for the environment by Toonol · · Score: 1

      Java and C# can both actually beat compiled languages because they can try multiple compiler strategies at run time and use the winner.

      That's the theory, and it's no doubt true... but I've never seem them come close in real life, and I doubt they ever have anywhere besides very non-representative benchmarks.

      But it's not really that relevant, because even if the execution speed is 10:1 in favor of one language, language execution speed is only one of the bottlenecks. They'll be spending a fair amount of time outside of the language, executing the same APIs. There's network speed, disk access, shared libraries... a 10:1 difference might not be that significant when only 10% of the time is spent actually executing the program.

    36. Re:php is bad for the environment by Anonymous Coward · · Score: 0

      Java and C# can both actually beat compiled languages because they can try multiple compiler strategies at run time and use the winner.

      ... but thanks to the garbage collector constantly running in background, in the end compiled languages still win.

    37. Re:php is bad for the environment by Toonol · · Score: 1

      The sad thing is that the open-source community hates flash (with *very* good reason)

      I don't think they do (have a very good reason, I mean). There's a good reason to hate the way Flash is USED, I agree; but many people hate flash as a language or platform, and there's really not much of a reason to. It's similar to Javascript in that way, a decent language that's condemned because of the way it's typically used; that's more a problem in the browser model than it is with Flash/Javascript themselves. The only strong criticisms of Flash that are really earned are its processor intensiveness, and perhaps that it's proprietary.

    38. Re:php is bad for the environment by Dragonslicer · · Score: 2

      Wrong - the language makes a huge difference. Try using the c api and CLIENT_MULTI_RESULTS and CLIENT_MULTI_STATEMENTS and concatenating 10,000 queries into one request, then using mysql_next_result() to get the next result set (no, not the next row, the next result set - 0 or more rows).

      One connection. Not 10,000. A BIG difference in execution time.

      Are you trying to imply that PHP establishes an entirely new connection to the database for every query? If so, you basically lose all credibility you might otherwise have.

    39. Re:php is bad for the environment by Surt · · Score: 1

      Nah, the garbage collector will outperform custom memory management every time. The best experts in the field have looked at the garbage collector. Have they looked at your memory management code?

      --
      "Who is the Journal of Quantum Physics going to believe?" --Stephen Hawking
    40. Re:php is bad for the environment by frostband · · Score: 1

      What's a "data-heavy" application?

      Facebook

    41. Re:php is bad for the environment by Pieroxy · · Score: 1

      The sad thing is that the open-source community hates flash (with *very* good reason), but hasn't brought forth any legitimate alternatives.

      HTML5+CSS3 is all we should ever need in the next few years. Other than that, if you need more, Flash and/or JavaApplets are fine. But only if you specifically need to.

      Of course, it will never be used because f****ng M$ decided no to include it in its 40%+ market share browser, so that noone can decently propose this for a large website. But it is another story, right?

    42. Re:php is bad for the environment by Rei · · Score: 1

      Either way, the key is to use the tool that's best for the job. I have an app that uses html and javascript on the frontend to asynchronously call programs on the backend. For simple calls, such as database queries, I call python scripts, since they're quick and easy to write for that purpose. For more CPU-intensive backend tasks, I call C++ programs.

      Language purity isn't a good thing, Everything has its strengths and weaknesses,

      --
      Nobody pushes buttons like our bunny. Big red buttons with labels that say "IGNITION", apparently.
    43. Re:php is bad for the environment by Anonymous Coward · · Score: 0

      Thank you for contributing nothing to the discussion. "Data-heavy" in this case means some kind of poorly designed frankenwebsite where the data is handled in the application side where PHP becomes a significant bottleneck instead of in the database where it's supposed to. If Facebook in fact was one of these sites then it would never have survived to even become a blip on anyone's radar.

    44. Re:php is bad for the environment by Narishma · · Score: 1

      You keep saying that, and it may be true in theory, but all the applications written in managed languages that I've used have been slower and used a lot more resources than the equivalent written in compiled languages.

      --
      Mada mada dane.
    45. Re:php is bad for the environment by Surt · · Score: 1

      That's likely to be due to them using cross platform ui libraries. Those libs are terrible, and can't even come close to the native accelerated libs. If you need a highly performing UI, don't use a cross platform language and API to do it.

      --
      "Who is the Journal of Quantum Physics going to believe?" --Stephen Hawking
    46. Re:php is bad for the environment by tomhudson · · Score: 1
      php only executes one statement at a time. I explain it here. It also has to re-initialize the memory arena for each execution of the script. That also sucks up a lot of time and resources. Also, most people run their servers to kill off a working thread after 500 requests to help reclaim memory leaks. If you code everything in c, you can make sure that there are no memory leaks (run a few million requests and you'll quickly know if you're leaking), so you never have to kill off threads.

      All these mean better performance. WAY better performance.

    47. Re:php is bad for the environment by upuv · · Score: 1

      This guy was talking non-sense. 1-10. If I was executing a single use once ever to run piece of code maybe this would be true. But facebook would never execute a line of code once.

      In reality the ratio is more like 1-1.2. For well written code on both sides of the fence. Code that runs a LOT.

      Also a large scale env would have plane and simple implemented a ton of optimizations for caching, CDN, that would make the choice of language almost moot. The language choice really boils down to the choice of lead arch and his/her favorite resume boosting tech of the moment. Of course you stuck with that choice for much longer than anyone ever guesses.

      Language pro-con this that and the other thing become part of the hallway conversations that eat up valuable time. I always go with what will get me to market the fastest. I can't worry about if I made the wrong choice in languages simply because in two years one of the other languages may be better. It's just too hard to see out farther than 6 months.

    48. Re:php is bad for the environment by furball · · Score: 1

      Objective-C with garbage collection turned on blows away Objective-C with garbage collection turned off on Snow Leopard. I believe it is on the order of 20x faster. Objective-C is a compiled language.

    49. Re:php is bad for the environment by dfgchgfxrjtdhgh.jjhv · · Score: 1

      ...get things done more than 10 times faster, than in C++

      That's the whole point. A server's time is much cheaper than a developer's. Even for Facebook it's going to be totally uneconomic to write everything in C. Maybe they'd benefit from writing a few routines in C where the extra performance is needed. For smaller websites even that would be a total waste of time & money.

      The code is much more portable in php too.

    50. Re:php is bad for the environment by shaitand · · Score: 1

      one word, vlan

    51. Re:php is bad for the environment by shaitand · · Score: 1

      He said 20k connections, as in web requests, not client computers. And its not a valid excuse in that case. The arp table is cached for fuck sake.

    52. Re:php is bad for the environment by CAIMLAS · · Score: 1

      You're not considering the fact that there would be no product without PHP. So really, 7,500 servers for facebook, if they were using C++, is probably a bit of an over-estimation. :)

      (That said, it's pretty evident that PHP was the wrong language for what they're doing. Python or Java, or even Perl would've been better choices. Arguably, .NET would be better, too, were it not for the likely architectural overhead in such a choice.)

      --
      ~/ssh slashdot.org ssh: connect to host slashdot.org port 22: too many beers
    53. Re:php is bad for the environment by moosesocks · · Score: 1

      The CPU-intensiveness alone is reason enough to despise it!

      Although the windows version is borderline-acceptable, Flash absolutely crawls on Mac and Linux boxes (the PPC mac versions were particularly bad, and no PPC linux version ever existed).

      I'm sorry, but a 320x240 YouTube video should *not* bring a modern system to its knees. VLC can play .FLV files using no more than 5% CPU on my fairly unremarkable 1.66 GHz Core Duo Mac Mini.

      The fact that a hacked-together reverse-engineered codec performs 20x faster than the official implementation is just sad.

      (As much as I want to love the HTML5 video element, there's little realistic chance of it actually being used unless Microsoft hop on board, and we all agree on a standard codec. Theora fits the bill, but isn't a particularly good codec compared to the proprietary options)

      --
      -- If you try to fail and succeed, which have you done? - Uli's moose
    54. Re:php is bad for the environment by Anonymous Coward · · Score: 0

      It would indeed be interesting to compare the environmental impact of flash ads to that of animated gifs or plain images.

    55. Re:php is bad for the environment by shaitand · · Score: 1

      "Are you trying to imply that PHP establishes an entirely new connection to the database for every query? If so, you basically lose all credibility you might otherwise have."

      PHP reuses a connection within a script but afaik every time a client requests dbrequest.php from the browser that script loads in its own little world and starts up its own personal connection to the server. A script making three requests uses one connection, but a script requested 12 times uses 12 connections.

      I believe he is saying that when 20k people simultaneously request data, having a memory resident C app grab all the concurrent data requests in a single swipe and reusing the same connections eternally for all page requests its much faster.

    56. Re:php is bad for the environment by ls671 · · Score: 1

      Java saves machine code to recall it next time.

      So most of the time, Java use machine code, no interpretation at all. Go on and learn about sophisticated optimization algorithms that are incorporated inot the JVM, several JITs and the like.

      I has become a field where very brilliant people work, they are probably ranking above the average developer ! ;-)

      --
      Everything I write is lies, read between the lines.
    57. Re:php is bad for the environment by Wraithlyn · · Score: 1

      PHP reuses a connection within a script but afaik every time a client requests dbrequest.php from the browser that script loads in its own little world and starts up its own personal connection to the server

      Incorrect, PHP can indeed maintain persistent DB connections across multiple requests.

      http://php.net/manual/en/function.mysql-pconnect.php

      "the connection to the SQL server will not be closed when the execution of the script ends"

      --
      "Mind, as manifested by the capacity to make choices, is to some extent present in every electron." -Freeman Dyson
    58. Re:php is bad for the environment by ls671 · · Score: 1, Troll

      > also get things done more than 10 times faster, than in C++.

      For me, JSP and Java classes get things done more than 10 times faster than PHP. Heck, use struts and hibernate and you have just gained another 10 times and more security with regards to SQL injections and other topics.

      Of course, there is a little of overhead in learning how to use the tools that, in my experience, I found most PHP developers are not willing to invest in. But once that overhead covered, it is done, you only have to learn it once..

      --
      Everything I write is lies, read between the lines.
    59. Re:php is bad for the environment by Surt · · Score: 1

      I think you probably meant to reply to someone above me ... my post is in complete agreement with yours.

      --
      "Who is the Journal of Quantum Physics going to believe?" --Stephen Hawking
    60. Re:php is bad for the environment by shaitand · · Score: 1

      Perhaps the reasons for his differences can be found in this quote from that same page then:

      "* Apache does not work well with persistent connections. When it receives a request from a new client, instead of using one of the available children which already has a persistent connection open, it tends to spawn a new child, which must then open a new database connection. This causes excess processes which are just sleeping, wasting resources, and causing errors when you reach your maximum connections, plus it defeats any benefit of persistent connections. (See comments below on 03-Feb-2004, and the footnote at http://devzone.zend.com/node/view/id/686#fn1)"

      He clearly said that he was not using apache but custom c to handle requests.

      In any case. He is obviously talking about a completely custom server app, load balancing, etc. That is a far different debate than writing server side cgi in php vs the same in c.

    61. Re:php is bad for the environment by Glonoinha · · Score: 1

      In my opinion the biggest benefit of compiled C code over Java code, particularly in highly dynamic workloads without a known peak load - is that the C code can allocate memory on the fly to expand to meet the needs of the workload, releasing that memory when it has finished the peak. With Java (not sure about C#, but I'm guessing C# also) the implementation team has to decide in advance how much memory the JVM could possibly need in the worst case scenario and pre-allocate that memory at application startup. Since determining the peak resource usage is a bit of a challenge even after hand tuning it manually a few times watching the system monitors, most apps are configured to use way more memory than they actually need ('just in case'.) It doesn't take too many applications configured to run using 256M, 512M or even 1024M - and you've literally sucked down all the memory in your machine and need to add another box.

      Perhaps the 1:10 ratio isn't just about the raw code execution performance, but possibly enhanced by the ability to provision more concurrent instances on the same machine. Granted you're still limited by the other factors (database performance, I/O, etc) but if you can process 40 concurrent requests because your machine can run 40 instances of the same handler, vs 10 concurrent instances in an interpreted or VM based language - that's where I see the performance benefit.

      --
      Glonoinha the MebiByte Slayer
    62. Re:php is bad for the environment by acroyear · · Score: 1

      there's also the whole question of "what is the bottleneck". hint: it ain't the php servers, its the database (and its mirrors). this is true for any web app - most of the "power" of such a huge database app is in transaction handling and the like, and in that, the underlying php code is itself written in C++ - these servers will be doing the same amount of work (for this part of the process, 80/20 rules and all that) no matter what the rest of the http/html processing code is doing.

      --
      "But remember, most lynch mobs aren't this nice." (H.Simpson)
      -- Joe
    63. Re:php is bad for the environment by hunterpaw · · Score: 1

      I have no axe to grind against PHP. PHP has its place. But when you reach the size of Facebook you need to use something that will scale better. I must say though, that the dozen or two errors I encounter daily using Facebook are handled rather well. But then, if they were not using PHP I seriously doubt there would be so many errors.

    64. Re:php is bad for the environment by dotgain · · Score: 1

      Whoosh!

    65. Re:php is bad for the environment by Alarash · · Score: 1

      The TCP Setup Rate (new TCP connections/second) and Concurrent TCP connections are actually two very important metrics that can kill your network, and therefore your network-dependant application. Those are very CPU intensive for both the network devices and (even more) servers. You don't need 20,000 client machines from a class B subnet to kill that. If you have 2,000 connections per second and your firewall, SLB, reverse proxy, server or whatever can handle only 1,000 with a reasonable response time, you are in trouble because then it doesn't matter if you use PHP or C++ (layer 7), because you network is the cause of the issue. This is why there are testing companies (Spirent, Ixia, Agilent and others) that exist. They first test the network layers, then move up the layers and test directly against the servers. You'd be surprised to see how many times the bottleneck come from the network - either because of cheap hardware, poor design or configuration errors.

    66. Re:php is bad for the environment by Joutsa · · Score: 1

      But it's not really that relevant, because even if the execution speed is 10:1 in favor of one language, language execution speed is only one of the bottlenecks. They'll be spending a fair amount of time outside of the language, executing the same APIs. There's network speed, disk access, shared libraries... a 10:1 difference might not be that significant when only 10% of the time is spent actually executing the program.

      The point here is not to run the code faster. It is to use 10% of the original CPU power to run the code in the same time. Which leads to savings in hardware costs, electricity, air conditioning, even floor space. Of course, this is only the PHP frontend part and does not affect the database backend, but still I hear that the PHP frontend takes some significant processing power.

    67. Re:php is bad for the environment by snemarch · · Score: 1

      ...and you assume they write their data-mining tools in PHP just because the "end-user experience" is written in that language?

      --
      Coffee-driven development.
    68. Re:php is bad for the environment by Anonymous Coward · · Score: 0

      This. A data-heavy application is, by definition, IO-bound. There's simply no way there's be a large gap in performance between C++ and PHP when the DB is the bottleneck.
      C++ can be 10x+ faster than PHP on CPU-heavy applications, but who the hell uses it for that?

      Also, I call BS on the GP's assertion that

      I was able to run totally illegal constructs, with plain text right in the middle of the code, and it ran, doing nothing of what I expected it to do.

      If you paste plain text in the middle of your code, you'll get yourself a parse error and that's it.

      Have we been trolled?

    69. Re:php is bad for the environment by acroyear · · Score: 1

      and the point of many others on the pro-php side is that there would be far MORE errors if it was written as a c++ application, due to what they see as that language's inherent complexities and lack of readability. I quit C++ for pretty much that very reason 13 years ago. Modern C++ is, in my opinion, self-obfuscating.

      Now, PHP is also obfuscated now, for much the same reason - supporting multiple programming techniques (procedural, fake OO, and now real OO), large numbers of old deprecated libraries with different coding standards, and examples that poorly separate concerns (MVC) leading to bad mixes of logic and rendering until one goes out of their way to learn a template engine (and there's zillions of those, too).

      But I don't have time for the mundanities of memory management and crap like that, especially when trying to figure out what the policy is for some library and how it is different from the next library I use, and for that matter, just how many libraries for C++ are out there, open-sourced and actively supported and maintained?

      If FB was rewritten from scratch, to the design it is now (keeping in mind this is now effectively the 4th major iteration of it), then a C++ implementation would certainly be more efficient, if still more expensive from a developer resource perspective (C++ programmers are rare and expensive, 'cause nobody wants to work in it anymore because of all that tedium). But once written, it would be frozen because C++ produces generally far less maintainable code in my experience because of its difficulty and lack of readability.

      Web applications in non-critical fields (and social networking is certainly non-critical) have to evolve, often and easily, and c++ does not provide that - it is better for a web app to risk a little instability than it is to provide 99.99% uptime but be impossible to change.

      --
      "But remember, most lynch mobs aren't this nice." (H.Simpson)
      -- Joe
    70. Re:php is bad for the environment by donscarletti · · Score: 1

      Seriously, here are the tests: pidigits, reverse-complement, regex-dna, k-nucleotide, n-body, fasta, binary-trees, fannkuch, spectral-norm, mandelbrot.

      Considering mandelbrot took 116x as much CPU time on PHP than C++, I would say that the 10x is probably more of a guesstimate of what Facebook would use. That said, it is still quite high compared to my guesstimate, but it isn't naive enough to assume those tests represent Facebook performance.

      --
      When Argumentum ad Hominem falls short, try Argumentum ad Matrem
    71. Re:php is bad for the environment by FlyingBishop · · Score: 1

      No, he assumes they write their data-mining tools in PHP because TFA claims that most of their servers are running PHP. Though maybe that just proves they aren't doing that much data mining. (Or if they are they're outsourcing to Microsoft, which would make sense since that's where they get their ads.)

    72. Re:php is bad for the environment by RivieraKid · · Score: 1

      It doesn't take too many applications configured to run using 256M, 512M or even 1024M - and you've literally sucked down all the memory in your machine and need to add another box.

      Except the host OS will most likely use lazy memory allocation - i.e. it will allocate virtual address space, but will only allocate physical memory when it is actually used. The end result is that even after requesting 4GB of memory, if I've only written to 128MB of it, then I've only got 128MB allocated from the host.

      On the other hand, if you request, and then immediately use all that memory, then yes, you are going to have issues (which is why a C malloc followed by memset is bad).

      --
      "Necessity is the plea for every infringement of human freedom. It is the argument of tyrants; it is the creed of slaves
    73. Re:php is bad for the environment by FrankDerKte · · Score: 1

      Ah, that must be the reason real-time systems disable garbage collection. It's just more efficient and outperforms manual memory management all the time.

    74. Re:php is bad for the environment by Surt · · Score: 1

      No, they disable it because it has a space cost and real time systems are almost universally on small devices. Also, it outperforms manual memory management on average, but real time systems care about peak, not average.

      --
      "Who is the Journal of Quantum Physics going to believe?" --Stephen Hawking
    75. Re:php is bad for the environment by Surt · · Score: 1

      You know that the jvm can be configured to allocate more memory on demand, right? Your statement just isn't factual, and hasn't been for at least the last several years.

      --
      "Who is the Journal of Quantum Physics going to believe?" --Stephen Hawking
    76. Re:php is bad for the environment by ls671 · · Score: 1

      > I think you probably meant to reply to someone above me

      indeed, my mistake, I am sorry about that...

      --
      Everything I write is lies, read between the lines.
    77. Re:php is bad for the environment by Mr2cents · · Score: 1

      It all depends, if the functionality you're writing is called all the time, it might very well be worth it to optimize the thing. A similar example: when I got the RAM size for an embedded application below 512KB, this saved a lot of money to the company I work for just by the sheer volume of units they sell each year (what was is, something like 3$/unit * 3000 units/yr - numbers could be off). The economics go further than just "faster to write".

      PS: Yes, SRAM is very expensive.

      --
      "It's too bad that stupidity isn't painful." - Anton LaVey
    78. Re:php is bad for the environment by FrankDerKte · · Score: 1

      True, I just wanted to point out that most arguments here can be proven wrong by one counter example.

      Nearly everything in engineering involves a tradeoff. So arguments leading to statements like language a is better than language b are nearly always wrong.

      Also garbage collection is turned off in real-time systems not because of space complexity but because of time complexity. For real-time systems the important factors are the deadlines for given tasks.

      Additionally, normally garbage collection does not improve the time complexity of an algorithm but the space complexity, because it avoids memory leaks and possibly fragmentation.

    79. Re:php is bad for the environment by Surt · · Score: 1

      Hence my comment about peak vs average performance in regards to real time systems. Real time systems can't have the large peak of a garbage collector, so they give up the superior average performance it provides.

      Garbage collectors reduce the overhead cost of each memory collection by reducing the number of calls to memory collection, and thus typically provide superior average performance. It's a sort of reverse amortization.

      --
      "Who is the Journal of Quantum Physics going to believe?" --Stephen Hawking
    80. Re:php is bad for the environment by Glonoinha · · Score: 1

      I recognize that you can specify a maximum memory allocation for the JVM, and can specify a minimum starting memory allocation for the JVM - and I appreciate the implications to the garbage collection routines based on the spread between the two.

      I have four minor issues (to which I alluded, but never really called out) with this strategy, and over time they cause the statement I made to become fact.
      a) Even though the JVM only initially allocates the Xms, eventually (and often fairly quickly) it will allocate the Xmx and treat the Xms as merely a goal during a GC.
      b) I can't say I've ever seen a JVM ever return memory to the OS after allocating a large chunk in order to process a memory intense transaction.
      c) Hand tuning the memory parameters for a fairly large application with an unknown anticipated workload is a fairly expensive process (labor costs.) What's the next setting used if 256M isn't enough? 512M of course. If that isn't enough? "Crank it up to 768M or throw a full Gig at it, I'm tired of farking with it and I have a backlog of projects to work on."
      d) And what happens when 512M is sufficient for 99.9% of your workload (including 100% of your test cases) but once a month you get hit with a peak that requires 520M to process? The thing dies a horrifically spectacular death in production, in slow motion, with everybody watching. And you can't reproduce it, because the business req docs didn't include that one case, so you run it through your performance regression tests again for weeks, unable to duplicate the problem. The ability to dynamically allocate (and then de-allocate) an extra 10M of memory to the process just cost weeks of wasted effort on top of a production failure.

      I like Java, don't get me wrong - coding up front end web based applications in C would be an expensive venture, given the existing base of development tools, environment extensions and developer talent. There would need to be a pretty serious scalability issue (known in advance, by a company on a project with resources to finance it up front) to warrant such an approach - but pre-allocating all the memory an application could ever use (ever!) makes for an environment that doesn't use the hardware to its full capacity, often being very wasteful. And I think that's what the original article was about.

      --
      Glonoinha the MebiByte Slayer
    81. Re:php is bad for the environment by Surt · · Score: 1

      a+b = what paging is for. Java (sun vm) doesn't return allocated memory and trusts the os to do the right thing.
      c+d = set Xmx to the max you can allocate to a process, and trust paging per a+b. Otherwise, if you consider a native process, what is a runaway memory allocator going to cost you?

      --
      "Who is the Journal of Quantum Physics going to believe?" --Stephen Hawking
  2. people use PHP? by Anonymous Coward · · Score: 1, Insightful

    I remember when it was the script kiddie's substitute for cgi-perl. What does it offer from a theoretical and engineering PoV, apart from a Visual Basic learning curve?

    1. Re:people use PHP? by jsdcnet · · Score: 4, Informative

      It's got a very rich set of features that are aimed straight at making web development dead simple. The syntax is fairly straightforward and familiar, being a typical mishmash of shell scripting, C and perlisms. It was built from day one to integrate with Apache, it's not a nasty bolt-on hack like mod_perl. It's in-process so there's no startup overhead like with CGI. I've been using it on some pretty large web sites for years and it's never let me down.

      --
      no longer working for cnet
    2. Re:people use PHP? by Anonymous Coward · · Score: 0

      It's got a very rich set of features that are aimed straight at making web development dead simple.

      PHP has very few web-related features. It can handle HTTP headers, cookies, sessions, GET and POST, escaping for HTML and URLs... and that's about it.

      The syntax is fairly straightforward and familiar

      Straightforward, apart from all the stupid special cases.

      It was built from day one to integrate with Apache, it's not a nasty bolt-on hack like mod_perl.

      mod_perl is neither "nasty" nor "bolt-on" nor a "hack".

    3. Re:people use PHP? by Lord+Byron+II · · Score: 5, Insightful

      I use it because I can code up relatively fast, relatively secure dynamic websites in a very short amount of time. I can install it on a webserver in seconds and it integrates beautifully with Apache and MySQL. Maybe there is a better solution out there, but PHP has always done what I need it to and I've never had a problem with it. It's never given me a reason to look elsewhere.

      What I don't understand is all of the PHP-haters out there. Really, who cares if it is "the script kiddie's substitute for cgi-perl"? Isn't the proper measure of a tool if it does what you need it to and not who else uses it?

    4. Re:people use PHP? by wampus · · Score: 1, Informative

      So your entire argument is "nuh-uh?"

    5. Re:people use PHP? by Pteraspidomorphi · · Score: 5, Insightful

      It wouldn't be so popular in first place if it was worthless. I wonder how much CO2 would be released into the atmosphere by the cars and computers of all the extra coders necessary to develop in C++ a website that could otherwise be developed in PHP, in the same period of time and with all other things equal. This is the same tired argument that can be used against *any* interpreted language. I love C++ - it's my favorite programming language - but I always use PHP for website development and I'll go on using it unless I'm forced not to.

    6. Re:people use PHP? by nxtw · · Score: 1, Insightful

      It's got a very rich set of features that are aimed straight at making web development dead simple.

      No, features that make web development "dead simple" are those that actually do something to make web development simpler - such as built-in form input validation based on a set of easy to define rules, or generating a set of pages to create/read/update/delete data based on a database schema.

      The syntax is fairly straightforward and familiar, being a typical mishmash of shell scripting, C and perlisms.

      You contradict yourself.

      It was built from day one to integrate with Apache, it's not a nasty bolt-on hack like mod_perl.

      Patently false. PHP has no dependency on Apache now, it originally used CGI, and continues to support CGI, FastCGI, and operation as a module in web servers other than Apache (such as IIS). The CGI startup overhead problem has many solutions, such as FastCGI, AJP, proxying, etc.

      It's in-process so there's no startup overhead like with CGI

      But "not in-process" does not imply the use of CGI, and it does not imply the use of any system with long loading times. Furthermore, "in-process" is potentially insecure and can be less reliable - as all code runs in the same process.

    7. Re:people use PHP? by harlows_monkeys · · Score: 2, Insightful

      It was built from day one to integrate with Apache, it's not a nasty bolt-on hack like mod_perl. It's in-process so there's no startup overhead like with CGI

      So mod_php is not a nasty bolt-on hack?

    8. Re:people use PHP? by hardburn · · Score: 5, Insightful

      mod_php has never integrated into Apache nearly as deep as mod_perl did. That is, lower level Apache APIs are not exposed to PHP. Using mod_php is an acceptable replacement for CGIs, but mod_perl does a lot more than that. That means taking over the entire server life cycle handlers to the point where, in Apache2, you can implement (say) a Gopher server if you want.

      mod_perl is not a hack. PHP, as a language and an API, very much is.

      --
      Not a typewriter
    9. Re:people use PHP? by afabbro · · Score: 1

      PHP isn't BAD...it just isn't very GOOD either. The random inconsistencies in functions (strpos, str_split, substr - which is it? Do we put underbars between name parts or run them together?) and the way things are different from other languages for no apparent reason or benefit (as if just to be different) annoy programmers. There's a lot of "it feels tacked on" in PHP, and while other languages have things tacked on, they don't feel quite as awkward about it (e.g., Perl, Java).

      To me, PHP feels like something the voodoo magician cooked up in his hut, while other languages feel like they came from the Wizard's Academy. It works, but it's no beauty.

      --
      Advice: on VPS providers
    10. Re:people use PHP? by Anonymous Coward · · Score: 0

      Seems to me that pointing out that your claims are false is a good counter-argument.

    11. Re:people use PHP? by dunkelfalke · · Score: 1

      No it isn't. It's just contradiction.

      --
      "It's such a fine line between stupid and clever" -- David St. Hubbins, Spinal Tap
    12. Re:people use PHP? by nietsch · · Score: 0, Offtopic

      dear AC. I am amazed by your insights, you truly must be one of those hyper productive programmers that is some order of magnitude more productive than his peers. How else can you do yourself what you advise other here? So you come here visiting with your own built webbrowser. Firefox just did not have some features you needed and putting them in an extension would be heresy. Better to built your own. Same goes for your house, your car, or your language. I pity the fools that do not understand you because they choose to ignore your superior language. What do you mean they had different requirements and built their own? Akkadjoembah!

      --
      This space is intentionally staring blankly at you
    13. Re:people use PHP? by VGPowerlord · · Score: 1

      mod_php has never integrated into Apache nearly as deep as mod_perl did. That is, lower level Apache APIs are not exposed to PHP. Using mod_php is an acceptable replacement for CGIs, but mod_perl does a lot more than that. That means taking over the entire server life cycle handlers to the point where, in Apache2, you can implement (say) a Gopher server if you want.

      And that's why mod_perl is a hack, while mod_php is just a module.

      --
      GLaDOS for President 2016! "Well here we are again. It's always such a pleasure." -- GLaDOS, 2011
    14. Re:people use PHP? by Anonymous Coward · · Score: 0

      And that's why mod_perl is a hack, while mod_php is just a module.

      No, mod_perl gives you the same ability to extend Apache in Perl as the builtin module system gives you in C. How can you consider that a hack? Is it a hack when any other application provides an embedded Perl/Python/Ruby interpreter for extensibility?

    15. Re:people use PHP? by nxtw · · Score: 1

      And that's why mod_perl is a hack, while mod_php is just a module.

      In no way does it make mod_perl a hack. mod_perl simply has more functionality than mod_php or any CGI environment can provide. It enables Perl to be used to extend the web server, whereas mod_php just lets you run PHP code in the same process instead of having to use CGI.

    16. Re:people use PHP? by Anonymous Coward · · Score: 0

      your skills are out of date, go away.

    17. Re:people use PHP? by rootofevil · · Score: 2, Funny

      I came here for an argument!

      --
      turn up the jukebox and tell me a lie
    18. Re:people use PHP? by mjwalshe · · Score: 1

      realy you have never had a bug caused by magic quotes or any of the other nastly little hacks that PHP has built up over the years.

    19. Re:people use PHP? by SendBot · · Score: 1

      I'm sorry, but I'm not allowed to argue unless you've paid!

    20. Re:people use PHP? by moosesocks · · Score: 3, Interesting

      Actually, both parent and GP are right. PHP is wonderful for web development, but has more than a few annoying quirks with regard to consistency.

      On the flipside, it has hands-down some of the best documentation on the planet, which makes the quirks tolerable, and is a big part of the reason why the language is so popular (especially with new programmers)

      I'm seriously hoping that a new PHP release finally clears up all of the inconsistencies in the main namespace once and for all. It'll be painful at first, but a very-good-thing in the long term. Updating old scripts could even be a semi-automated process, given that the necessary changes are extremely superficial.

      --
      -- If you try to fail and succeed, which have you done? - Uli's moose
    21. Re:people use PHP? by poopdeville · · Score: 1

      There's hardly any difference between the two. The only question is which hooks Apache normally calls, and which hooks the mod_p*'s call. You can easily fold in, say, URL re-writing into a PHP module if you really wanted.

      --
      After all, I am strangely colored.
    22. Re:people use PHP? by Dr.Syshalt · · Score: 1

      It's in-process so there's no startup overhead like with CGI.

      It's funny you mention it, since the best (performance-wise) way to handle PHP is FastCGI. mod_php is not thread-safe so it can't be used with Worker or Event Apache MPM's. Prefork MPM - the only one that works with mod_php and its multiple extensions - just sucks in terms of performance.

    23. Re:people use PHP? by EEDAm · · Score: 1

      No you didn't!

    24. Re:people use PHP? by Dr.Syshalt · · Score: 1

      PHP is wonderful for web development, but has more than a few annoying quirks with regard to consistency

      Uh... no. PHP is the Windows of www programming. It's a mediocrity of web languages. It's a something that "everyone uses". It's a broken language that teaches everyone broken patterns of programming (like mixing HTML and code), but it's easy to start and it's everywhere.
      That's why it's widespread. Not because it's "wonderful" for something.

    25. Re:people use PHP? by FiloEleven · · Score: 1

      No you didn't.

    26. Re:people use PHP? by Anonymous Coward · · Score: 0

      This is inciteful but shouldn't be modded down. PHP is responsible for some of the most retarded design decisions ever invented in web programming. (And this shitty injection-prone code is still out there and running.) Plus the whole 'accelerator' nonsense is solely because someone is trying to commercialize the language, it really should be built-in.

    27. Re:people use PHP? by Anonymous Coward · · Score: 0

      > It's a broken language that teaches everyone broken patterns of programming (like mixing HTML and code)

      Really. I've never had PHP "teach me to mix HTML and code." Of course, it's quite possible and easy to do - just like it was with Perl and Cold Fusion. Just because some "Teach Yourself PHP in 3.14 Hours" book told you to do it is not the fault of the language.

      Actually, given the choice between a PHP that allows mixing code and markup, and one that doesn't, I'd pick the version that allows it. Just because there are times when it's appropriate and expedient to stick a few variables into an HTML document and be done with it, rather than waste a developer's time wrestling with a templating system.

    28. Re:people use PHP? by gbjbaanb · · Score: 1

      amen. Use the right tool for the job.

      PHP has plenty of benefits to a coder, easy to use, lots of examples out there, and easy to deploy. I tried to install Python-based ReviewBoard recently and it was a nightmare (shame really), but all the PHP-based sites I deply (eg mantis, dotProject, MediaWiki) just work without any hassle at all. If only all website deployments were as easy in other languages they'd probably be more popular.

      However, once you've written your site, and its become really popular, you owe it to your balance sheet to recode it in something somewhat more efficient (not Java, k) so you don't have to buy 30,000 servers in the first place. Now you know the code, its well documented, and has good interfaces, then recoding it in C++ should be easy. Bear in mind those extra coders required to write it in C++ are going to be employed one way or another, so they don;t get to be included in your site's carbon footprint. Also, those extra coders will not be needed once the infrastructure is written, and they're still going to be a fraction of the energy cost of running Facebook for a few more years.

    29. Re:people use PHP? by hardburn · · Score: 1

      [citation needed]. I've been googling around, and it does not appear that the Apache API is exposed to PHP at all.

      --
      Not a typewriter
    30. Re:people use PHP? by Anonymous Coward · · Score: 0

      You realize URL re-writing is a string parsing and rendering function, right? And that you can write functions like that in PHP, right? You don't need to touch the Apache API to do URL rewriting.

    31. Re:people use PHP? by shovas · · Score: 5, Insightful

      Your post is really annoying. Did you mean to be so obnoxious? And +5, Insightful. Come on, php isn't popular with slashdotters but whatever one calls reverse fanboyism it isn't cool either.

      No, features that make web development "dead simple" are those that actually do something to make web development simpler...

      Absolutely. And PHP does it. That's why it's so popular. There may be even more that can be done but if no popular language is doing it already that argument is kind of pointless.

      You contradict yourself.

      No he doesn't. You might not like scripting / dynamic languages but taking the best (or a good stab at taking the best) of scripting, C and perl can actually make some things more straight-forward. Need a regular expression? Used to function calls rather can syntactical regex? Need perl regex? preg_match.

      Patently false. PHP has no dependency on Apache now, it originally used CGI, and continues to support CGI, FastCGI, and operation as a module in web servers other than Apache (such as IIS). The CGI startup overhead problem has many solutions, such as FastCGI, AJP, proxying, etc.

      Patently missing the point. PHP and Apache go together so well it created the LAMP mindshare space.

      But "not in-process" does not imply the use of CGI, and it does not imply the use of any system with long loading times. Furthermore, "in-process" is potentially insecure and can be less reliable - as all code runs in the same process.

      Who cares? His point is startup cost which is generally higher for forks vs modules and you're just plain going to get more scalability compared to the traditional perl cgi forking method. Hence mod_perl.

      Give me a break. You can dislike anything you want but why do you even bother when you don't have all the facts.

      +5, Insightful. Dear me...

      --
      Selah.ca. Pause, and calmly think on that.
    32. Re:people use PHP? by hardburn · · Score: 1

      You realize there's way more to the Apache API than URL handling, right?

      --
      Not a typewriter
    33. Re:people use PHP? by hardburn · · Score: 1

      Algebra is such a hack, too. People should stick with addition and subtraction. And even subtraction should just be done with addition of negative numbers.

      --
      Not a typewriter
    34. Re:people use PHP? by moosesocks · · Score: 1

      Care to enlighten us of languages that do it better?

      --
      -- If you try to fail and succeed, which have you done? - Uli's moose
    35. Re:people use PHP? by Just+Some+Guy · · Score: 1

      On the flipside, it has hands-down some of the best documentation on the planet

      ...except for everything else. If you think PHP.net is nice, then you've never experienced something like pydoc (or any other system that makes it trivially easy - and common - to embed useful comments directly into the source). PHP.net is good for reminding you that foo_bar1($needle, $haystack) has a different calling convention from fooBar2($haystack, $needle) and giving visitors a place to argue about which is better.

      --
      Dewey, what part of this looks like authorities should be involved?
    36. Re:people use PHP? by moosesocks · · Score: 1

      pydoc's great in the same way that manpages are great.

      However, given that it's 2009, I'd like to take advantage of what HTML and the web have to offer.

      If I forget the syntax for strcmp, I can simply type 'www.php.net/strcmp' into my browser, and I'll get the right page, complete with syntax highlighting and user-contributed notes in the event that the official documentation is inadequate and/or confusing.

      If I forget the function name and type
      'www.php.net/strcomp,' the search engine usually picks up on my error, and redirects me to the right page.

      That all said, Python does have pretty good online documentation, and is a nice language in its own right.

      --
      -- If you try to fail and succeed, which have you done? - Uli's moose
    37. Re:people use PHP? by shaitand · · Score: 1

      "PHP has very few web-related features. It can handle HTTP headers, cookies, sessions, GET and POST, escaping for HTML and URLs... and that's about it."

      Yeah.. that's pretty much all there is to server side web development. MySQL has become pretty much standard for web and it has built-ins for that too.

    38. Re:people use PHP? by shaitand · · Score: 1

      PHP is very evil. In large part PHP can be blamed for the neglect of many prior to PHP well maintained perl modules.

      Of course perl modules are a nightmare in a binary package management world. Do I use CPAN or do I use the binary package? What is the binary package named? Is there any chance in hell that the module in a language that is all about modules will be available in the windows world? What type of insane hoops will I have to go through to get a unix type development platform built on my windows server in order to compile said module?

    39. Re:people use PHP? by Ego_and_his_own · · Score: 1

      PHP is one of the best web development platforms! It provides best start-up tool and a wide door towards hi-end development. PHP abilities amazes me. It provided me a door to Linux world, c++ world, Java world, DB world, RIA world,... On windows it provided me door to the COM components, services, .NET... If you are not happy with performance, its easy. Create library in C++ or use one. And people PHP is written in C++. Facebook is best proof that PHP is robust enough to handle large scale development. That is painful to language specific haters... One thing i LOVE about PHP is that it handles dirty code. This is something, considering that I come from creative world, that gives me freedom in sketching ideas. So far I didnt find better tool for this kind of R&D.

    40. Re:people use PHP? by nxtw · · Score: 1

      Absolutely. And PHP does it. That's why it's so popular. There may be even more that can be done but if no popular language is doing it already that argument is kind of pointless.

      PHP is simpler than using some language without any builtin Web support. But its web functionality isn't much more sophisticated than what was in CGI libraries a decade ago. You neglected to address the specific examples of things that other systems do that make web development significantly easier.

      No he doesn't. You might not like scripting / dynamic languages but taking the best (or a good stab at taking the best) of scripting, C and perl can actually make some things more straight-forward. Need a regular expression? Used to function calls rather can syntactical regex? Need perl regex? preg_match.

      There is nothing straightforward about much of PHP.

      Patently missing the point. PHP and Apache go together so well it created the LAMP mindshare space.

      There was no point to miss. The first post stated as fact that PHP was built to integrate with Apache from the start. Not that PHP works well with Apache or is commonly used with it. PHP and Apache are easily separated, and PHP applications can be used on any web server supporting CGI/FastCGI.

      Who cares? His point is startup cost which is generally higher for forks vs modules and you're just plain going to get more scalability compared to the traditional perl cgi forking method. Hence mod_perl.

      The poster asserted that PHP was built to integrate with Apache from the start (which is false) and that mod_perl is a "hack". Both are false. I also mentioned some of the problems with using the in-progress approach of mod_php.

    41. Re:people use PHP? by nxtw · · Score: 1

      Yeah.. that's pretty much all there is to server side web development.

      Other web platforms/frameworks often have features like automatic forms processing and validation, automatic generation of CRUD pages based on a database schema, built-in user authentication and security, etc. as well as more sophisticated templating support.

      There are many PHP libraries providing such functionality. But what comes with PHP out of the box is rather limited.

    42. Re:people use PHP? by Anonymous Coward · · Score: 0

      And yet, managed/shared database connections in PHP are impossible. Ergo you often have a situation (as you might observe on facebook, if you've ever used it) where a database connection is unavailable.

    43. Re:people use PHP? by shaitand · · Score: 1

      I don't think I would WANT that level of generic coding applied. The bloat would be phenomenal. I seriously doubt you could name such as platform/framework that could scale to slashdot or facebook level traffic.

      I mean hell, why not just skip all that and have a language with a complete CMS library built in. At some point your language isn't a language anymore, its a script for an application.

    44. Re:people use PHP? by nxtw · · Score: 1

      I don't think I would WANT that level of generic coding applied. The bloat would be phenomenal. I seriously doubt you could name such as platform/framework that could scale to slashdot or facebook level traffic.

      I've described features in ASP.NET and in many frameworks for Java, Ruby, Python, etc... There's nothing really bloated about any of these features. The code only needs to be generated once. As for sites that can scale to these levels of traffic: Just about everything Microsoft does is in ASP.NET. MySpace moved to ASP.NET. There are many commercial sites using Java.
      Java and ASP.NET will compile entire pages to JVM/CLR bytecode.

    45. Re:people use PHP? by Anonymous Coward · · Score: 0

      This is inciteful ...

      "Inciteful," LOL. Cute way to write "Troll," it does lend itself to confusion with the insightful mod though.

    46. Re:people use PHP? by shaitand · · Score: 1

      "I've described features in ASP.NET"

      Like I said, bloat. Next you'll be claiming VB is fit for actual use.

      "and in many frameworks for Java, Ruby, Python, etc... "

      That wouldn't be included in the language any more than PHP which is far more tuned to the web than any of those languages.

      "As for sites that can scale to these levels of traffic: Just about everything Microsoft does is in ASP.NET."

      It claims to be. Microsoft jumps through a lot of hoops to run their own software and they aren't above hacks to make it happen. Just look back at when they were caught running all their web services using BSD.

      "There's nothing really bloated about any of these features. The code only needs to be generated once."

      The overhead isn't in code generation, the overhead is in the bloated inefficient code that is generated. Targeted granular usage tailored and specific code is always going to be more efficient than general purpose code. The more general and larger the function the general purpose code is supposed to fit, the more bloated and less efficient it needs to be to be. Every potential scenario that code needs to cover requires trade offs in performance an efficiency.

      In a small site that may not matter, but that bloat and inefficiency adds overhead that increases as the site scales.

    47. Re:people use PHP? by nxtw · · Score: 1

      Like I said, bloat. Next you'll be claiming VB is fit for actual use.

      Do you have any technical arguments regarding ASP.NET, or just bias and sarcasm based on a product last updated in 1998?

      That wouldn't be included in the language any more than PHP which is far more tuned to the web than any of those languages.

      Indeed. But people use frameworks with these languages. How many PHP developers use any frameworks? Many don't.

      It claims to be. Microsoft jumps through a lot of hoops to run their own software and they aren't above hacks to make it happen. Just look back at when they were caught running all their web services using BSD.

      Citation needed.
      Hotmail started on FreeBSD and some of their outsourced services (like caching via Akamai) may use Linux.

      The overhead isn't in code generation, the overhead is in the bloated inefficient code that is generated. Targeted granular usage tailored and specific code is always going to be more efficient than general purpose code.

      So you know about every system in existence and know they all generate inefficient code?

      The more general and larger the function the general purpose code is supposed to fit, the more bloated and less efficient it needs to be to be. Every potential scenario that code needs to cover requires trade offs in performance an efficiency.

      In this case, using SQL on a web application is a huge source of inefficiency. Those queries need to be passed from the client to the server, and then the server needs to parse them and then figure out how to return the data... so bloated and inefficient. Why don't they just use custom data structures instead?

      In a small site that may not matter, but that bloat and inefficiency adds overhead that increases as the site scales.

      And if that's the case, the inefficient parts of any code can be rewritten or replaced.

    48. Re:people use PHP? by Anonymous Coward · · Score: 0

      Exactly. I started on C and C++, and have recently done C# and Java web programming.

      We did similar apps in PHP in a quarter or less of the time, and they actually ran many times faster with the very basic magic of an opcode cache and mod_gzip. The PHP site I worked for merged with a Java shop and the Java team got ripped into for taking months to do what our team did in weeks or days.

      Now as an "enterprise" developer at my latest job, I talk to experienced C# lead developers who manually remove the white space from their HTML to improve download speed. ??? And the hodgepodge of java web frameworks piled on buggy java app servers is even worse.

      If you want to do web programming, use the right tool to get the job done right and fast. Developers and development time cost a business a hell of a lot more. People saying "do web development in C" have never worked on a real website.

    49. Re:people use PHP? by rtb61 · · Score: 1

      In reality the real decision is not whether to PHP or C++ but, whether to add a compiler to PHP. The performance of any compiled code is bound to the quality of the compiler and what it can do with the wild interpretive code you feed it.

      Examples are of course http://www.phpcompiler.org/ and http://www.roadsend.com/home/index.php. So are larger web companies wasting resources and energy simply by failing to pre compile PHP rather than sticking to on the fly compilation.

      --
      Chaos - everything, everywhere, everywhen
    50. Re:people use PHP? by Anonymous Coward · · Score: 0

      The documentation and built-in feature set are indeed two of the biggest reasons PHP is such a great and successful language.

      The consistency thing, I don't buy at all. Between documentation, IDEs, and basic testing, things like "i don't like this argument order" are a moot point. PHP is much too old to go dicking around with core functions and arguments for no good reason other than anal retentiveness.

    51. Re:people use PHP? by aqk · · Score: 0

      Oh, BS!

      You sound like one of those old Macintosh weenies. (almost extinct now)
      Some things never die. I guess they have now morphed into Linux-Perl weenies.

      But seriously- why cannot a PHP (or Perl) compiler be built? There are so many interpreters nowadays and very few compilers.
      I used to code mainframe crap 30 years ago (Assembler, COBOL, FORTRAN etc)... and then people discovered real-time interpreters. But hey- cycles were cheap. If the code could be compiled ONCE, instead of each time, it would save a lot of CPU cycles and by extension, electrical power and heat. PHP compiler anyone? Or even PERL?

    52. Re:people use PHP? by dmuir · · Score: 1

      APC will be included in PHP6. Bytecode caching has not really been a huge issue in PHP until more recently with larger MVC frameworks being used.

    53. Re:people use PHP? by Anonymous Coward · · Score: 0

      If I forget the syntax for strcmp, I can simply type 'www.php.net/strcmp' into my browser, and I'll get the right page, complete with syntax highlighting and user-contributed notes in the event that the official documentation is inadequate and/or confusing.

      My experience is that most users contributing are just contributing their own hacks, and looking at them should convince anyone that they have no clue at all what they're doing. I wouldn't be surprised if these user contributions are responsible for more bugs and security vulnerabilities than the built in PHP hacks themselves are.

    54. Re:people use PHP? by dkf · · Score: 1

      However, once you've written your site, and its become really popular, you owe it to your balance sheet to recode it in something somewhat more efficient (not Java, k) so you don't have to buy 30,000 servers in the first place. Now you know the code, its well documented, and has good interfaces, then recoding it in C++ should be easy. Bear in mind those extra coders required to write it in C++ are going to be employed one way or another, so they don;t get to be included in your site's carbon footprint. Also, those extra coders will not be needed once the infrastructure is written, and they're still going to be a fraction of the energy cost of running Facebook for a few more years.

      It's not at all clear that rewriting your site from PHP to C++ would save that much (websites are I/O bound, not CPU bound) and while you might be able to reduce the number of servers a little bit, the cost of such a rewrite (indeed, of a rewrite from anything to anything) is pretty high in itself. For one thing, the chances of screwing up the rewrite are pretty high; it's a non-trivial quantity of code to convert. Plus if you're rewriting your site, you're not adding value to it in other ways.

      The cost of carbon is far too low to justify an expensive rewrite.

      --
      "Little does he know, but there is no 'I' in 'Idiot'!"
    55. Re:people use PHP? by gbjbaanb · · Score: 1

      you're assuming that Facebook is an unmaintainable, messy, poorly-defined, poorly-implemented mess of PHP code.

      oh wait.... :)

    56. Re:people use PHP? by intheshelter · · Score: 1

      You're an idiot. All his points were valid and your rebuttals made no sense since they all consisted of straw man arguments. If you don't want to use PHP then fine, but STFU with your inaccurate and disingenuous rebuttals.

    57. Re:people use PHP? by RivieraKid · · Score: 1

      Oh! This is Abuse. You want room 12-A next door.

      Stupid Git!

      --
      "Necessity is the plea for every infringement of human freedom. It is the argument of tyrants; it is the creed of slaves
    58. Re:people use PHP? by shutdown+-p+now · · Score: 1

      How many other tools, apart from PHP, did you properly try?

    59. Re:people use PHP? by shutdown+-p+now · · Score: 2, Informative

      I remember when it was the script kiddie's substitute for cgi-perl. What does it offer from a theoretical and engineering PoV, apart from a Visual Basic learning curve?

      Market penetration. From managerial perspective, you can hire PHP developers a dime a dozen, and replace them very quickly if needed. From developer perspective, you can grab any of those "PHP in 10 nanoseconds for complete idiots" books, an Apache+PHP+MySQL bundle installer for Windows, and learn it in a few days to the level sufficient to be hired.

      Of course, the typical quality of a PHP solution is what you'd expect from such approach, but when did it ever stop anyone?

      If you mean technological advantages, than there are none whatsoever. As a language, PHP today is essentially Java with weak typing, no proper packages, namespaces just being introduced (so no existing library uses them), and some very questionable language design decisions (like $a[1] is the same element as $a["1"], but $a["01"] is distinct).

      From library perspective, the coverage is okay - about what you'd expect from a decent modern platform - but API design is essentially random and inconsistent with no common guidelines followed, and things such as Unicode support are usually an afterthought.

      In short, there's nothing there over Python or Ruby, or even Groovy or Boo.

      As to why it ended up in the spot it is in? Well, it's actually fairly obvious when you look at the history. PHP version 4, the point at which its popularity skyrocketed, was released in 2000. At that point the established frameworks were ASP (not ASP.NET - that didn't exist yet), JSP, and ColdFusion. Mentions of MVC at this point, in the context of Web development, would just earn you some blank stares; at best, some particularly advanced Java devs would be aware of "model 2", handcoded via servlets and JSPs...

      ColdFusion was both getting dated, and cost $$$. The latter bit especially meant that it was right out for many.

      ASP was really simplistic, with VBScript as a primary language (and that was much more primitive than PHP), no decent IDEs, and not exactly fast either; also, while it was kinda free itself, you needed IIS to run it, and that (in 2000, remember?) came with Win2K, which not everyone in the "casual newbie developer" group had or even wanted to have, and which was more expensive than 9x/ME (meanwhile, Apache ran on 9x).

      JSP itself was okay in this context, but it had two problems compared to PHP. First of all, Java is still a rather verbose language, and that complexity showed when you don't have anything like modern frameworks mapping requests to beans etc. At that point, you had to work with raw request parameters (strings!), query database in raw SQL, and output plain text data (strings!) - and while you can do that all in Java, the corresponding PHP code was usually much shorter. As well, no-one in PHP land cared about the theoretical advantages of database decoupling that JDBC gave you, because they (we, really; I was doing it at that time as well) just hardcoded mysql_* calls, because that's all that was expected to be supported in the foreseeable future.

      The other problem JSP had was setting it all up. Today, you can just download Netbeans and get it all out of the box configured properly; back then, it usually involved getting JDK first, then downloading and configuring Tomcat (not for the faint of heart, too). I don't recall seeing any all-in-one, one-click setup bundles like there were for PHP.

      And documentation. Oh yes, that still persists as a myth that "PHP has the bestest docs" (witness various fanboi replies in this thread). It hasn't been true for a few years at least, but back then it definitely was. The big deal was that PHP manual somewhat tutorial-like - something you could read without having any clue as to how it all works, and get the general idea along with the minimum of details that you actually need to get it all working. Meanwhile

    60. Re:people use PHP? by Anonymous Coward · · Score: 0

      Give me a break. You can dislike anything you want but why do you even bother when you don't have all the facts.

      +5, Insightful. Dear me...

      Jealousy. That is THE reason for all the anti-php bitchin. Oh, the language that used to make me cool did not led me to many achievements, I can always go on and on about how theoretically bad some other language is. ....Honestly? Go and be productive using your language, whatever it is. I guess that's what PHP programmers are doing while you call them 'script kiddies that write poor code' Guess what, facebook climbed to position #2 of the most visited websites on the whole web, right after google... and they make extensive usage of PHP which is a language said to be 'not suitable for heavy traffic websites'. Accept that. If you like other language then it's all good, stick with whatever you like or are more productive at, why would you go bitch about stuff you don't like if you don't have to use it?

    61. Re:people use PHP? by tolan-b · · Score: 1

      Never had a magic quotes bug no. Standard practice is to disable it and has been for a long time.

      You could list some of your other favourite PHP hacks and we can see from there eh...

    62. Re:people use PHP? by tolan-b · · Score: 1

      Actually my friend wrote the original PHP in 24 hours and he's a rabid layer separation proponent! :)

      His later book "PHP Object Patterns and Practice" is much more interesting though.

    63. Re:people use PHP? by mjwalshe · · Score: 1

      ah you have neaver had to fix some other programmers PHP then. If you are stating from scratch you can avoid a lot of the nasty's

    64. Re:people use PHP? by Ego_and_his_own · · Score: 1

      How many other tools, apart from PHP, did you properly try?

      I use C#, Java(EE), Python, AS3, PHP, MySQL, Linux on all my projects. It just happens that each of them for me has it good purpose for specific tasks. I use technology by its benefits(performance and interoperability) and speed of development not by plain preference (like I know that and I stick to it).

    65. Re:people use PHP? by shutdown+-p+now · · Score: 1

      I use C#, Java(EE), Python, AS3, PHP, MySQL, Linux on all my projects.

      Nice, that gives some basis for discussion. Now, can you specifically contrast PHP against, say, Python, and explain why PHP is a better "web development platform"?

    66. Re:people use PHP? by Ego_and_his_own · · Score: 1

      Now, can you specifically contrast PHP against, say, Python, and explain why PHP is a better "web development platform"?

      I think I have explained that in the first post. That is in general, for individual tasks like system interactions, parsing, some network programming i use python. As I am building custom solutions, I don't have much use of py web frameworks. And usual tasks are much faster done in PHP than in python.

  3. Would be a non-issue by Anonymous Coward · · Score: 0

    if there was a run-time compiler solution for PHP!

    1. Re:Would be a non-issue by theNetImp · · Score: 3, Interesting
    2. Re:Would be a non-issue by Anonymous Coward · · Score: 0

      I'd assume that he means a Just-In-Time-Compiler that translates the PHP code to native code during runtime, just like moden Java runtime environments or Firefox and Safari do for Javascript. For PHP there are of course APC, eaccelerator, Zend Platform etc. that cache and/or optimize the compiled bytecode, which just isn't as good as native code.

  4. Assumes PHP Dev Effort = C++ Dev Effort by VampireByte · · Score: 5, Funny

    What about all the cycles compiling and debugging C++ code? Or all the trees torn down for C++ books? Or the environmental impact of C++ developers? I mean, have you ever had to share a cube with one of them? Pheewww.

    --

    Run and catch, run and catch, the lamb is caught in the blackberry patch.

    1. Re:Assumes PHP Dev Effort = C++ Dev Effort by LBt1st · · Score: 4, Insightful

      I know your being funny but you've got a good point. Developing and maintaining C++ code is not like developing and maintaining PHP script. Which of course is why we have PHP to begin with. It's designed for the web and ease of implementation. Sure C++ would be faster running but not necessarily more efficient in terms of dollars.

    2. Re:Assumes PHP Dev Effort = C++ Dev Effort by sznupi · · Score: 3, Funny

      Have no fear, turning devs into disposable resources will ensure bright future to efficiency being judged only in hardware terms.

      --
      One that hath name thou can not otter
    3. Re:Assumes PHP Dev Effort = C++ Dev Effort by ilguido · · Score: 1

      Or the environmental impact of C++ developers?

      Are you assuming that C++ developers don't live when they're not coding?

    4. Re:Assumes PHP Dev Effort = C++ Dev Effort by Anonymous Coward · · Score: 0

      OMFG zombies!

    5. Re:Assumes PHP Dev Effort = C++ Dev Effort by Anonymous Coward · · Score: 2, Interesting

      "Sure C++ would be faster running but not necessarily more efficient in terms of dollars."

      I guess that's the question: is there a net economic benefit to switching from php to C (or C++) for the sake of runtime efficiency, given that running that many servers does cost a fair chunk of money? If you are writing your code for a personal server or a few dozen, obviously it doesn't pay. Development and maintenance costs dominate. And the performance ratio being assumed here (10:1) is probably ridiculous, in part because the runtime costs of PHP are mitigated by caching. But a few thousand servers? It's hard to be certain anymore. Even a 10% saving might be worth quite a bit.

      How much does a typical developer cost versus a potential saving of 1000 servers? What is the human to server runtime cost ratio? And how many developers would it take to actually replace and maintain php with C/C++ code? (It would probably take more than the number of PHP programmers, and they'd probably cost more per person, and I question whether it would be as maintainable)

      In any case, it wouldn't be as simple an analysis as the article implies. That much is certain.

    6. Re:Assumes PHP Dev Effort = C++ Dev Effort by Penguinisto · · Score: 1

      True, but who would want to eat a Soylent Developer?

      Yuck.

      --
      Quo usque tandem abutere, Nimbus, patientia nostra?
    7. Re:Assumes PHP Dev Effort = C++ Dev Effort by Anonymous Coward · · Score: 0

      Developing and maintaining C++ code is not like developing and maintaining PHP script.

      Yeah, it requires half a brain. Which too many people claiming to be software engineers these days are lacking.

    8. Re:Assumes PHP Dev Effort = C++ Dev Effort by __aasqbs9791 · · Score: 1

      Most bosses I've had already chew developers up and spit them out. This would save them that last step!

    9. Re:Assumes PHP Dev Effort = C++ Dev Effort by Anonymous Coward · · Score: 0

      I know your being funny but you've got a good point. Developing and maintaining C++ code is not like developing and maintaining PHP script. Which of course is why we have PHP to begin with. It's designed for the web and ease of implementation. Sure C++ would be faster running but not necessarily more efficient in terms of dollars.

      Perhaps not necessarily more efficient in terms of dollars, but more green, is what the article is arguing. Our fellow Americans surely know that being economical dollar-wise and being ecological is not the same goal ?

    10. Re:Assumes PHP Dev Effort = C++ Dev Effort by BitZtream · · Score: 0, Flamebait

      It won't be more efficient in terms of dollars if you're trying to have PHP flunkies write C code.

      PHP will only be cheaper because anyone can write PHP code that appears to work. Keyword: Appears.

      Maintaining C code is not difficult, it just requires discipline, which would benefit PHP developers as well, unfortunately most are just some guy/girl who read a web page describing PHP and so they played with it, then got them a job writing it for some place that didn't know any better.

      Writing PHP code is like cooking dinner at home, anyone can do it, and it will rarely kill anyone, but it will just as rarely come out great.

      Writing C code is like being a doctor. If you do it will, have discipline and a solid work ethic, you can perform what appears to be miracles to people used to PHP, likewise, you can far easier screwup a buffer and kill the application and make it VERY difficult to find.

      The problem is, a good developer would do THE EXACT SAME PROCESS regardless of what language he or she uses.

      The real problem is that 'php writers' aren't developers. Thats why most of them don't follow proper procedures for developing software and think the process is somehow different than C dev.

      If you think the PHP dev process is different than the C/C++ dev process, then you don't really shouldn't call yourself a developer, you are a php writer at best, not even a good one.

      --
      Persistent Volume manager for Kubernetes - https://github.com/dwimsey/openshift-pvmanager
    11. Re:Assumes PHP Dev Effort = C++ Dev Effort by raju1kabir · · Score: 1

      Writing C code is like being a doctor. If you do it will, have discipline and a solid work ethic, you can perform what appears to be miracles to people used to PHP

      Ok, I'll bite.

      I've done long stints as both a professional C developer and a professional PHP developer.

      What's an example of something you can do in C that appears to be a miracle to someone used to PHP? I assume we are keeping this within the realm of things that PHP is actually used for, and you're not going to talk about writing device drivers or compilers.

      --
      "Patriotism is your conviction that this country is superior to all other countries because you were born in it." -- GBS
    12. Re:Assumes PHP Dev Effort = C++ Dev Effort by Trogre · · Score: 1

      So... why not just compile the PHP (into C++ or directly into asm) and be done with it?

      --
      "Nine times out of ten, starting a fire is not the best way to solve the problem." - my wife
    13. Re:Assumes PHP Dev Effort = C++ Dev Effort by MikeFM · · Score: 1

      I'd argue that well made systems in PHP aren't that much less efficient than C++. The language is less important than good caching and good code design. Most of the heavy work takes place in the database and in backend code anyway. Backend processing usually takes place in apps already written in C and maybe more efficient mid-level languages such as Python and Java.

      Any sane coder doesn't write whole apps in C/C++ anymore than they do in Asm. If something needs a boost you rewrite that small part into C. Write the majority of code in an easier to write and maintain language.

      --
      At what price learning? At what cost wisdom? The price is a man's peace of mind, and the cost is his life.
    14. Re:Assumes PHP Dev Effort = C++ Dev Effort by Arker · · Score: 1

      Not *necessarily* cheaper, true. I would say the point to take away, however, is that it *can* be cheaper in the long run, if your site is expected to have a long run in the first place, and if it is serving a high volume of pages. This could really be generalised to any software application. People generally justify using scripting languages instead of programming generally by pointing out that it's cheaper to spend 10 times as much on a faster computer for a script kiddy to work on than to hire a proper programmer, and that it's cheaper to buy an office full of new computers than to wait an extra two weeks for development in many cases. True enough, at that scale it often is. However scale is a factor normally ignored, and should not be. Ten times the cost of equipment for one developer is one thing, and ten times the power usage may not be a blip on the radar at that scale, but ten times the initial outlay, physical space, power usage etc. on a large server farm is an entirely different story. That adds up quick, and makes the case for hiring real programmers (if there are any left to be hired) and doing the job properly.

      --
      =-=-=-=-=-=-=-=-=-=-=-=-=-=-
      Friends don't let friends enable ecmascript.
    15. Re:Assumes PHP Dev Effort = C++ Dev Effort by WinstonWolfIT · · Score: 0

      You need to look at the upfront cost of the C++ developer -- including his personal impact on the environment -- against the ongoing higher cost of php. What's the ROI of a doubled development footprint against a 1/10 maintenance footprint? 1 year? 10?

    16. Re:Assumes PHP Dev Effort = C++ Dev Effort by MikeFM · · Score: 1

      If you don't think C/C++ is harder to write and maintain than PHP then you're delusional. I've been coding for decades and started off in assembler and C and usually consider my code to be far cleaner and better written than most code.

      Sure you can write good C reasonably easy but it certainly does have a lot more gotchas than PHP. Discipline helps but in the end the language is still more likely to suffer bugs due to it's design. With C you have to think about more than the logic of your program. You have to worry about memory and buffers and lots of fun stuff like that.

      I will agree that many PHP programmers don't write very good code but I think that is hardly unique to PHP. I've seen plenty of really bad C. One of the biggest issues I've seen with C programmers is the insistence of writing code in C that shouldn't be in C. Then instead of having badly written easy to work with code you have badly written difficult to work with code. A great improvement.

      --
      At what price learning? At what cost wisdom? The price is a man's peace of mind, and the cost is his life.
    17. Re:Assumes PHP Dev Effort = C++ Dev Effort by Handlarn · · Score: 1

      Elitist much?

    18. Re:Assumes PHP Dev Effort = C++ Dev Effort by vtstarin · · Score: 1

      You have to include facebook users to this list too. Humans do breath out CO2 right.

    19. Re:Assumes PHP Dev Effort = C++ Dev Effort by yacc143 · · Score: 1

      Actually, in practice that is not even a given.

      Considering that in real life, development is constrained by money & time, you have in practice to compare a crude 1st implementation in C++ to a polished 2nd or 3rd implementation in PHP, Perl, Python or Ruby.
      And if you haven't got a 2nd implementation (or refactoring) going when using the dynamic bunch, then you wouldn't have a working C++ prototype in the timeframe. Guess in the case of Facebook, not having it would be a big win to privacy on the Internet, but you get the gist of the argument.

      And despite the myths, it's quite easy to write C++ code that is not efficient. Especially if you are in a hurry to get your first prototype going. Especially if you have not the best talent. (Which you seldom have).

    20. Re:Assumes PHP Dev Effort = C++ Dev Effort by vegiVamp · · Score: 2, Insightful

      > Sure C++ would be faster running

      If you take APC or similar compile caches into account, I think you'll find that the gap is remarkedly smaller than you'd expect. It'll never close entirely, but given that I've seen 20x speedups on some pages, the benefit is huge.

      --
      What a depressingly stupid machine.
    21. Re:Assumes PHP Dev Effort = C++ Dev Effort by Chrisq · · Score: 1

      Writing C code is like being a doctor. If you do it will, have discipline and a solid work ethic, you can perform what appears to be miracles to people used to PHP

      Ok, I'll bite.

      I've done long stints as both a professional C developer and a professional PHP developer.

      What's an example of something you can do in C that appears to be a miracle to someone used to PHP? I assume we are keeping this within the realm of things that PHP is actually used for, and you're not going to talk about writing device drivers or compilers.

      That restriction is a bit unfair. I could say what "miracles" could a doctor perform compared to my mum with a packet of band-aid. I assume that we are keeping things in the realm of things that a lay person with a packet of band aid actually deal with, like minor scrapes and cuts to the surface of the skin.

  5. Ridiculous by SashaM · · Score: 3, Insightful

    That's a ridiculous way to analyze it. What about the environmental impact of the extra time required to write the same functionality in C++? What about the impact of whole classes of C++ bugs that don't exist in C++ (and, perhaps, vice versa) with the downtime or security breaches resulting from them? Or a hundred other ways in which writing all that software in C++ would be different of which I can't think at the moment?

    1. Re:Ridiculous by Sygnus · · Score: 5, Funny

      What about the impact of whole classes of C++ bugs that don't exist in C++

      I've spent many a sleepless night worrying about C++ bugs that don't exist in C++. I'm glad I'm not alone.

      --
      First posting isn't trolling. It's...first posting. :) -- Illiad
    2. Re:Ridiculous by Anonymous Coward · · Score: 0

      What is ridiculous is that you are comparing the cost of the extra time programming in a single PC (okay, let's say 10 PCs) with the cost of maintaining 25000 servers all year when much more efficient languages (it doesn't have to be C) require much less horsepower and could suffice with 5.000 or less, as if they were on the same league.

    3. Re:Ridiculous by betterunixthanunix · · Score: 1

      "What about the environmental impact of the extra time required to write the same functionality in C++?"

      Should be about equal to the environment impact of maintaining the PHP language itself; in fact, it is likely to be less than that, since there would be no need to maintain the actual interpreter, but only duplicate some functionality. This is really a one-off, and the libraries could be reused by thousands of enterprises.

      Bugs and security breaches do not cause any more CO2 emission than bug-free code, so I do not really see your point in bringing them up. The other differences in development are pretty minor, since PHP derives its programming model from C.

      --
      Palm trees and 8
    4. Re:Ridiculous by Taur0 · · Score: 1, Insightful

      That's not an environmental impact at all. Hardly. What you're asking is: "What's the environmental impact of employing more programmers?" Sure, let's say worst-case, facebook hires programmers that would have got another job elsewhere, that other company must now hire different programmers and it trickles down eventually until some people who were going to be unemployed get a job programming somewhere. Okay, so now those people have a job. Let's ignore the fact that you're essentially saying that we should cut down emissions by making people unemployed. It's true that having a job will probably cause them to contribute a bit carbon emissions than if they were unemployed, but studies have shown that the large amount of our personal environmental impact is non-reducable (around 50%), even if you were to go homeless and live on the streets, we might see maybe a 10-20% increase of their personal carbon emissions. For even a couple dozen programmers that's nothing compared to running 20,000 more servers per year and that's absolute worst case. What you're arguing is the economic cost for facebook, whether it's worth all the man-hours to make their severs more efficient. That's debatable, but if you want an example, you just have to look at Google where they have a team that is devoted to increasing efficiency, despite the fact that they are already running some of the most power-efficient servers in the country.

    5. Re:Ridiculous by Anonymous Coward · · Score: 0

      What about the environmental impact of the extra time required to write the same functionality in C++?

      100 guys programming in C++ on their desktops is nothing compared to 30000 servers. So that doesn't make a lot of difference.

    6. Re:Ridiculous by Anonymous Coward · · Score: 0

      You're missing the biggest benefit. If they were coding in C++ then they would only be using about 100 servers and workstations as they still wouldn't have got it running, thus saving 29,900 servers. Then there's probably millions of clients which could have been turned off too.

    7. Re:Ridiculous by jolyonr · · Score: 1

      "(and, perhaps, vice versa)"

      Not only do you need to worry about the C++ bugs that don't exist in C++, but you also need to worry about the C++ bugs that don't exist in C++.

      Now, i'm not a mathematician, but I make that double the worry.

      Jolyon

      --


      Please read my Canon EOS tech blog at http://www.everyothershot.com
    8. Re:Ridiculous by SashaM · · Score: 1

      "What about the environmental impact of the extra time required to write the same functionality in C++?"

      Should be about equal to the environment impact of maintaining the PHP language itself; in fact, it is likely to be less than that, since there would be no need to maintain the actual interpreter, but only duplicate some functionality. This is really a one-off, and the libraries could be reused by thousands of enterprises.

      You're making a strange argument. Why does maintaining the C++ language have less of an environmental impact than that of maintaining the PHP language?

      Bugs and security breaches do not cause any more CO2 emission than bug-free code, so I do not really see your point in bringing them up.

      So having a person wake up and drive to work to fix something in the middle of the night doesn't cause any pollution? And that's just a very minor issue (and minor impact). Serious bugs and security breaches can create a lot of extra work with a lot of environmental impact.

      P.S. Due to the laws of thermodynamics, work is always (thermal) pollution :-)

    9. Re:Ridiculous by Anonymous Coward · · Score: 0

      C++ really is frustrating and difficult to work with, compared with modern languages that include less kitchen sink. Just an hour ago I again experienced the most vexing parse. I really hate that and it is proof of the horrible syntax of C++. They should have abandoned the C syntax. Linking to compiled C object files really is all compatibility you ever need.

      With all that said I am not convinced that PHP is much easier to develop.

    10. Re:Ridiculous by TheLink · · Score: 1

      No the environmental impact would be a lot less. Facebook would need a lot fewer servers if they used C++, but not for the reasons stated in the article.

      If facebook wrote everything in C++, the millions of people would still be using myspace and friendster, because the facebook team would still be busy writing and debugging.

      The very many lines of PHP code at Facebook aren't going to be easily replaced by something with far fewer lines of C++. If you think it's easy, go ahead and reproduce Facebook's functionality using C++, let me know when you're done.

      I don't like PHP, but there are very many good reasons to use a higher level language than C++.

      Yes, there are very good and very productive C++ programmers. But only a few of them. And there's a limit to how fast they can write code.

      So what wise people do is have them write stuff for the other programmers to use. You don't make the "normal" programmers write C++.

      --
    11. Re:Ridiculous by Anonymous Coward · · Score: 0

      Your reply is ridiculous too. You need extra time only during development. Just a small number of guys are needed to write code. They use a small number of computers, not 22500... By the way it's not so difficult to write code in c++ that will output just a string (the page). Maybe the real advantage is that one php coder costs less than a c++ one.
       

    12. Re:Ridiculous by Anonymous Coward · · Score: 0

      That's why the subject line is so apropos.

    13. Re:Ridiculous by Anonymous Coward · · Score: 0

      It sounds like a joke, but I spent a year once translating code written in C++ on unix to work in C++ on unix.

      You see, there are a bunch of areas in the C++ standard where behavior is "undefined". AIX (IBM's flavor of unix), and HPUX (HP's flavor of unix) have compilers that disagree in a lot of these areas. So when you have a project spanning twenty thousand source code files, written by folks who "knew" that they'd always be using the same compiler so it was ok to rely on these quirks...

      The worst difference was that on AIX, you actually can call functions on null pointers, those functions will just immediately return null. So, you'd get code where you'd see "if (foo()->bar()->baz()->qux()...)" as the method of checking for errors -- if any one of those functions returned null, the whole chain returned null, so your if statement was like a try-catch block. Of course, on any other flavor of unix, the "undefined" behavior of calling a function on a null object is defined as "seg fault, crash your program", so hitting the error condition would be fatal. Oops.

    14. Re:Ridiculous by misof · · Score: 1

      Most of all, the article is just plain wrong, especially in the last sentence "Their servers are only a tiny fraction of computers deployed world-wide that are interpreting PHP code." From what I've heard, Facebook does use PHP, but their PHP code is not interpreted, it is compiled using a custom compiler. And if you RTFA, it clearly states that Facebook developers implemented numerous optimizations that are not available in the default PHP distribution. There's no evidence that would support the "conservative ratio of 10 for the efficiency of C++ versus PHP code" in Facebook's case.

    15. Re:Ridiculous by Anonymous Coward · · Score: 0

      This is also known as a null-pointer dereference, which frighten programmers who have only used PHP and the like.

      But don't worry, there's a ton of non-existent fixes for that, some of which aren't even not hard at all, and when one gets accustomed to actually think about memory and addressing, leaving out the nonexistent bugs doesn't even invalidate the missing failure modes.

    16. Re:Ridiculous by Anonymous Coward · · Score: 0

      The behaviours of those bug objects initialized from the classes of C++ bugs that don't exist in C++ are implementation specific. Deriving classes from these classes of bugs results an ill-formed programme unless the derivation is performed by the MS compiler division. [ Note: other valid derivers from the classes of bugs currently include the compiler division of HP -- end note ]

    17. Re:Ridiculous by Anonymous Coward · · Score: 0

      That's not so much a problem with C++, as it is with you using two shitty C++ compiler implementations.

      I've run into this before. Do you know what the solution is? Use GCC if you're cheap, or Comeau C++ if you can spend a few dollars. Both run just about everywhere, and generate code that is optimized well enough for most applications. And both implement the language better than most other implementors.

    18. Re:Ridiculous by BitZtream · · Score: 1

      If you think languages other than C/C++ like PHP are immune to security issues, please PLEASE stop writing code.

      Buffer overflows are one class of exploits generally caused by inexperienced devs who don't have discipline. They just do something else stupid in languages that prevent buffer overflow issues internally. Instead that'll do something retarded like taking input directly from a web page and forming an SQL query rather than using a parameterized query.

      The only people who scream and shout about how a language fixes security issues are ones who don't know what they are talking about.

      Languages do not create security issues, they do not cause them, they do not fix them. All security issues are caused and solved by the developer.

      Stop blaming the language for your short comings.

      --
      Persistent Volume manager for Kubernetes - https://github.com/dwimsey/openshift-pvmanager
    19. Re:Ridiculous by Anonymous Coward · · Score: 0

      That's a ridiculous way to analyze it. What about the environmental impact of the extra time required to write the same functionality in C++?

      It's definitely on the same scale as of running tens of thousands servers for years, right? I mean C++ is complex shit, need to compile, wtf is that? How are the people with ADHD supposed to write code?

    20. Re:Ridiculous by Anonymous Coward · · Score: 0

      You see, there are a bunch of areas in the C++ standard where behavior is "undefined".

      To translate that from standard-speak, that means "do not do it." Simple as that. IOW, I generally treat such code regardless of platform as a bug. Expect the rare cases when that is needed to exploit the platform specific feature.

      AIX (IBM's flavor of unix), and HPUX (HP's flavor of unix) have compilers that disagree in a lot of these areas.

      But both of them for quite some time align on GCC. Specifically for C++, I'd advice to use GCC 4.x with -Wall. That's not bullet proof, but having dealt with Solaris/HPsUX/AIX porting problems, I like to have something I can align with and also GCC produces most informative warnings/error messages. They are big and often confusing, but during porting are irreplaceable. Of course, on any other flavor of unix, the "undefined" behavior of calling a function on a null object is defined as "seg fault, crash your program", so hitting the error condition would be fatal.

      Buy some memory debugger for AIX and let it chew the code on platform where it runs. Fix it where it runs. Then do porting. (On Linux with valgrind it's easy and free.... On HPsUX with Insure is doable. On Solaris with Purify is OK. But they cost money.)

    21. Re:Ridiculous by ltrm · · Score: 1

      Parent needs modding up! Again, PHP wouldn't be my cup of tea but if it gets you to market faster then use it. You can always reimplement in C++ once you've got the users.

    22. Re:Ridiculous by chdig · · Score: 1

      I agree with your comments, and would add that almost any professional PHP website with any complexity at all, uses one of the many optimizers (pre-compilers) available, which themselves are written in C. PHP can be used for easy development AND quick response times, if it's set up properly.

      Further, in terms of overall servers, thousands of Facebook's servers are sitting there with gobs of memory running memcached for caching responses. PHP executes a C library for access to it, and to toss out my own ratio, I'd say that far less than 1/10 requests to Facebook's servers require anything more than a cache lookup.

      PHP is quick to develop with, efficient when coded by professional developers (as one would expect Facebook's to be), and only as a result of its success, is responsible for some sort of environmental impact. Need a component to run faster? Write a C-extension for it, but PHP is fine as the primary language.

      C++ is not ideal for website development, other than in the most extreme of cases, and though it's open-source, there aren't exactly many (any?) successful web projects using it, so I don't understand why /. articles like this one even suggest it.

    23. Re:Ridiculous by Anonymous Coward · · Score: 0

      What kind of programmer needs 10000+ terminals to write a C++ application? Incompetency is the only reason C++ is not used to make those kinds of applications. I die a little everytime I remember I had to use MemCached in a RoR website.

    24. Re:Ridiculous by adamchou · · Score: 1

      Obviously, if you can't prove that the bugs don't exist, then they do.

  6. That's poor reasoning by Anonymous Coward · · Score: 0

    Very poor reasoning. What about the increased number of developers and their systems needed when using a lower level language. I also wonder what the impact of their servers compared to the impact of all of the user systems executing java script client side? Could that JS code be optimized to make the client side functions greener? Also, maybe investing time in optimization of the current code base to reduce server load would be a benefit. First Post ?

    1. Re:That's poor reasoning by Anonymous Coward · · Score: 0

      What's poor reasoning about it? The summary supposes 25000 servers running PHP. If more efficient C++ code lets them reduce the number of servers by 10% that's a fairly significant reduction of energy consumption.

      Lets say for the sake of argument that the energy requirements of the servers are equal to the energy requirements of the desktops used for code production. We'll neglect other energy requirement of the programmers by assuming those would be temporary for the most part and nonexistent after development of the more efficient code was complete.

      Are they developing the code on 25000 desktop computers 24 hours a day for a year? No? 2500 desktop computers 24 hours a day for a year? Even fewer desktops?

      Lets say they're developing more efficient C++ code for the servers on 250 desktops, 24 hours a day, for a year. Those 250 desktops would use 1% of the energy that the 25000 servers use. If after a year they came up with more efficient C++ code that allowed them to use only 22500 servers they'd have reduced their overall server energy consumption by 10% by expending 1% of their total energy consumption.

      Seems a fairly reasonable tradeoff. Would probably be reasonable at a 5% reduction. If they only got a 2% or 3% reduction it'd be questionable. Below that it'd be pointless.

    2. Re:That's poor reasoning by moz25 · · Score: 1

      Ah, but these points are not hard to counter.

      1. Needing more developers: more jobs for skilled programmers, which is *good*
      2. More developer systems: negligible compared to server farm reduction.
      3. Javascript client-side: already being optimized (see Chrome stories)

    3. Re:That's poor reasoning by moz25 · · Score: 1

      Considering a minimum cost per server in the range of $500-1000, 2500 servers equal between 1.25 and 2.5 million dollars...

      That's certainly a budget for which you could get some C++ programmers... ?

  7. Languages not for everyone by Darkness404 · · Score: 3, Insightful

    The thing that this article fails to see, is that some languages aren't for everyone. A PHP programmer who turns out good PHP code isn't going to magically make the same level of code for C++. It also doesn't see that Facebook can't be down for longer than an hour at most, otherwise risk user outrage. After all, they have many, many, many users and for it to go down for a day would be akin to Google going down for a day or so. The difference being that if Google is down for a day, most users can use Yahoo, Bing, Live, WolframAlpha, etc. to search. Not every Facebook user has a MySpace.

    --
    Taxation is legalized theft, no more, no less.
    1. Re:Languages not for everyone by Anonymous Coward · · Score: 4, Funny

      A PHP programmer who turns out good PHP code

      The Easter Bunny, Santa Claus, a PHP programmer who turns out good PHP code, and Steve Balmer are in the four corners of a room. In the center of the room is a chair. Who throws the chair first?

      Steve Balmer, because the other three don't fucking exist!

    2. Re:Languages not for everyone by Anonymous Coward · · Score: 5, Insightful

      > a PHP programmer who turns out good PHP code

      Yeah, that'd be me. Hi! We do exist, and there are plenty of us.

      Granted, we tend to be outnumbered 100:1 by the PHP programmers who produce complete crap. The same is probably true of nearly any language.

    3. Re:Languages not for everyone by Anonymous Coward · · Score: 3, Funny

      A PHP programmer who turns out good PHP code

      Ontological argument: A good PHP programmer is better than a PHP programmer that doesn't exist. Therefore a good PHP programmer must exist.

    4. Re:Languages not for everyone by Anonymous Coward · · Score: 0

      I don't believe you.

    5. Re:Languages not for everyone by digsbo · · Score: 2, Interesting

      Unfortunately, the C++ programmer who writes bad C++ code is more common than the C++ programmer who writes good C++, and the bad C++ is probably harder to rework than bad php.

      I once rewrote a bit of software that some MIT grads did. Theirs was 20K lines of C++, used 110 MB ram (constantly newing and deleting), used dozens of threads (constantly spawning and harvesting), and drove the system to its knees (90% system, 10% user load). My 2K (yes, one-tenth) lines of straight C used 5 threads (preallocated), a configurably preallocated ring buffer (about 100K in practice), and used less than 5% of user time with no measurable system load. And I was able to do this adding functionality and improving the reliability. Very few defects in 2000 lines of C.

      The moral of the story is that C++ is complex, and even really smart people can do awful things with it. And the awful things really smart people do are worse than the awful things average or below-average people do. The programmer should use the tool he knows best, and if the tool isn't the right one, learn it, or let someone else do it.

    6. Re:Languages not for everyone by orlanz · · Score: 5, Funny

      A self proclaimed good PHP programmer... yeah there are about a 100 of those to every 1 that doesn't do that.

    7. Re:Languages not for everyone by Pteraspidomorphi · · Score: 1

      Actually, that would be 90:10 (1/10), according to Sturgeon's Law. But because not everyone is a PHP developer, us good developers are unfortunately fewer than the amount of santas and easter bunnies needed to cover the entire world in their respective days...

    8. Re:Languages not for everyone by supernova_hq · · Score: 1

      ummm, What?

      (if I'm missing some obsucre reference, so be it)

    9. Re:Languages not for everyone by mhelander · · Score: 1

      No, a good PHP programmer _would be_ better than a PHP programmer that doesn't exist. It doesn't mean a good PHP programmer exists.

    10. Re:Languages not for everyone by butlerm · · Score: 0, Flamebait

      Yes. There are a lot of "smart" people who are horrible engineers, and college CS departments are full of them and turn out graduates with the same shortcomings.

      Ideally, "computer science" should become a sub-specialty of mathematics, all the CS departments in the world should be changed into software engineering departments, and all full professors in the department be required to have ten years of real world (read: non-academic) software or hardware engineering experience.

    11. Re:Languages not for everyone by RichardJenkins · · Score: 1

      My God! I must get to church!

    12. Re:Languages not for everyone by The+End+Of+Days · · Score: 1

      And I singlehandedly repelled the Nazi invasion of Russia while simultaneously impregnating 10,000 good Russian peasant women with the next generation of scientifically correct socialists.

      The moral of the story is that my story has just as much to do with the topic as yours does - except mine is true!

    13. Re:Languages not for everyone by Haxamanish · · Score: 1

      (if I'm missing some obsucre reference, so be it)

      This is what you're missing.

    14. Re:Languages not for everyone by moortak · · Score: 1

      Poorly worded theological argument reference. The ontological argument for god basically says that because existence is better than nonexistence a perfect god would have to exist. The argument requires perfect and not just good to even begin to make sense.

      --
      Xavier Rabourdin for president 2012
    15. Re:Languages not for everyone by digsbo · · Score: 1

      Ok, you got me. Seriously, though, I doubt I would have done as good a job if I wrote it in C++ and tried to do it in an OO paradigm, because that's harder to do well than to write simple procedural code. So to the point of the original story, C++ is an extremely sophisticated language, and assuming you can do everything better in C++ is only true if you're an expert C++ programmer. Likewise if you want to do things in any other language or paradigm for that matter.

      I forget where I saw it, but I read once that a study was done where a group of programmers were using Haskell or Eiffel to dome some project X. And they kicked butt. So another study was done, and everybody expected that the same results would be shown, and it would prove Haskell/Smalltalk/Eiffel was going to be the solution to all software engineering problems.

      The second time around the project took the same time and had the same defect rate as with a team doing it in C. What they found was that the first team were expert programmers, highly trained in the language in question, and the result was an artifact of that detail, not of the language.

      So since I was doing C in a highly idiomatic way, and it was something that I was comfortable with, I succeeded. The C++ guys were trying to do too much with their code, and failed. I see a lot of that. KISS.

    16. Re:Languages not for everyone by Anonymous Coward · · Score: 0

      I once rewrote a bit of software that some MIT grads did [from C++ to C and my version was way more awesome] ... The moral of the story is that C++ is complex, and even really smart people can do awful things with it.

      This is probably more of an indictment of MIT grads than C++. People selected to be "type A++" are going to get something done then move on to the next thing. Go go go. No time to go back and perfect what you've accomplished. This is my experience with software made by MIT grads.

    17. Re:Languages not for everyone by BitZtream · · Score: 1

      Nope, just a bunch of PHP writers who think they are good programmers.

      --
      Persistent Volume manager for Kubernetes - https://github.com/dwimsey/openshift-pvmanager
    18. Re:Languages not for everyone by Anonymous Coward · · Score: 0

      Different AC here- I'm a ZCE, and I took up PHP on the side an an experiment/project which turned into a fair bit of income. I otherwise have been doing DARPA contract programming for research (algorithms, DSP, etc) in C and C++ for over a decade (started C++ in 1994 with borland Turbo C++), C#/ASP.Net in there as well, and for another decade before that Pascal, Delphi and VB. Anyway, point is im a career software developer who also picked up PHP- does it not stand to reason I'm a good PHP coder as I am in C++? I have to sell myself, am I not allowed to say my qualifications?

    19. Re:Languages not for everyone by Anonymous Coward · · Score: 0

      Boasting your PHP prowess while posting as an AC? It appears you desperately wanted to claim the "I'm a great PHP coder" while avoiding to be identified and see your code being scrutinized. So I'll take your fantastic claim with a grain of salt.

    20. Re:Languages not for everyone by GreatBunzinni · · Score: 2, Insightful

      I once rewrote a bit of software that some MIT grads did. Theirs was 20K lines of C++, used 110 MB ram (constantly newing and deleting), used dozens of threads (constantly spawning and harvesting), and drove the system to its knees (90% system, 10% user load). My 2K (yes, one-tenth) lines of straight C used 5 threads (preallocated), a configurably preallocated ring buffer (about 100K in practice), and used less than 5% of user time with no measurable system load. And I was able to do this adding functionality and improving the reliability. Very few defects in 2000 lines of C.

      That's nice and all. I'm currently finishing my master's and for my thesis I'm writing an application in C++ and therefore I believe I'm in a similar situation as your MIT grads were. The thing is, in paper I have 1 year to finish my project, which could only start 2 months into the school year. Then it isn't very possible to properly design the application because, as the software is part of a research project, you are by definition learning the stuff as you go along. On top of that you have the ever common screw ups -- bugs, redesigns, rewrites... you name it. And if that wasn't enough, you have to do that part time, while juggling classes, meetings and presentations.

      That is a recipe for disaster. It isn't at all possible to spit out a perfectly oiled, academically immaculate application under those circumstances. Heck, I'm just a couple of months into my project and I already compiled a small list of features I should rewrite but that I can't as I can't afford the time. So it's perfectly natural that when someone looks into my code they say "hey, I can write this a whole lot better than him". Yes, you can. So can I, actually. Yet, I had to write that under circumstances that made it a whole lot harder to do a better job at it.

      Nonetheless, as you can attest to it, your MIT grads' application, although with it's flaws, does run just fine. Not perfectly but fine nonetheless. And if it's possible for some third party to pick up their work and reproduce the exact same functionality under less time and with such an ease that the people rewriting it can have the luxury of looking into details such as preallocating threads and ring buffers then that's a good sign they successfully accomplish what they aimed to do. And that's what really count.

      --
      Slashdot, fix your code or at least hire someone who is competent at it to do it for you.
    21. Re:Languages not for everyone by geminidomino · · Score: 1

      Why do I feel like I'm in a fucking Dr. Pepper commercial?

    22. Re:Languages not for everyone by Anonymous Coward · · Score: 0

      show us the money, I wanna see this good PHP code!

    23. Re:Languages not for everyone by mgblst · · Score: 1

      So you are saying there a million to 1 good PHP programmers to non-good. (yeah, we aren't very good at maths either).

      There are 3 types of PHP programmers in the world. Those that can count, and those that can't.

    24. Re:Languages not for everyone by vux984 · · Score: 1

      The difference being that if Google is down for a day, most users can use Yahoo, Bing, Live, WolframAlpha, etc. to search. Not every Facebook user has a MySpace.

      No, the difference being that if facebook went down, people would discover they didn't actually need anything it does after all.

      Sort of like when their cable goes out. You pace aimlessly for a few minutes, and then do something else with your new found free time.

    25. Re:Languages not for everyone by neoform · · Score: 1

      I'm one of those good PHP coders too! Check out my code!!!

      $query_login="select * FROM user";
      $result_login = mysql_query($query_login) or die("Query failed");
      //$login_check = mysql_num_rows($result_login);

      while($row=mysql_fetch_array($result_login))
      {
      $username=$row["username"];

      if ($username==$username1)
      {
          echo "<script>";
      echo "window.location.href='login_error.php?rec=qq';";
      echo "</script>";
          exit;
        }
      }

      --
      MABASPLOOM!
    26. Re:Languages not for everyone by Nyeerrmm · · Score: 1

      I realize that a lot of it is just good-hearted ribbing, but there seems to be a lot of discussion of PHP coders being bad coders, which is something I'm not sure I get. My background is as an aerospace engineer who ends up writing a lot of code, but I wouldn't call myself a developer, or even a *real* programmer by any stretch; I prefer to work in MATLAB, as its an industry standard and has built-in functions for much of what I need, but I've also written code in C, C++, C#, Objective C, Python, BASIC, JavaScript, probably some others, and yes, PHP.

      I've been using PHP for a couple of web-based projects I'm working on, and I've enjoyed using it. It has some rough edges, particularly with inconsistent function naming, and 'duck' typing does lend itself to some poor practices if you're not careful, but its been great for many of the things I'm trying to do. It integrates well with Apache and is dead-simple to work with on Linux and OSX. It lets you do OO stuff where appropriate but doesn't force it down your throat (sometimes you just need a simple conditional to display a chunk of html). You can call class names from variables making it easy to do automated form generation without running through tedious case statements. It facilitates access to 'GET' and 'POST' data and has adaptable data structures and good string manipulation functionality. And of course it makes it easy to interface with the database.

      Obviously, all of this leaves some room for abuse, and its certainly not perfect, but it doesn't mean its impossible to write decent PHP code. I like to think that with my projects I've done a decent job of keeping the code straightforward, maintainable and efficient -- moving database access into data model objects, keeping repeated segments of code, headers, etc. in distinct files so they only have to be modified once, using descriptive subroutine names so its obvious what the code is doing, planning out the overall program structure so I know how its all laid out in advance, and maintaining a MVC architecture where appropriate. The same kind of things you'd do to make the code 'decent' in any language.

      Sorry if I'm missing something.

    27. Re:Languages not for everyone by Anonymous Coward · · Score: 0

      Granted, we tend to be outnumbered 100:1 by the PHP programmers who produce complete crap. The same is probably true of nearly any language.

    28. Re:Languages not for everyone by Anonymous Coward · · Score: 0

      Don't worry, we won't get in the way of Java programmers who think they're hot shit because they spent 100 LoC to implement a singleton and pat themselves on the back because they didn't use a global variable.

    29. Re:Languages not for everyone by liam193 · · Score: 1

      You have to be a PHP programmer to understand PHP code well enough to say that it's bad. So is your statement a lie or are you a bad programmer?

      And I would submit that anyone who turns out bad PHP is not a good programmer in other languages either. The fact is that other languages may make it harder to turn out bad code, but if you program correctly, you shouldn't need the language ot make it hard. However, if you rely on the language to keep you out of trouble, you are going to eventually find a way around the language's protections.

    30. Re:Languages not for everyone by introspekt.i · · Score: 1

      Because Dr. Pepper is realllly good.

    31. Re:Languages not for everyone by DJ+Rubbie · · Score: 1

      Just call yourself a programmer with a fluent understanding of proper programming methodologies (which is knowing how to separate out business/presentation logic, writing unit tests, etc.) The language you work with should be secondary to that.

      --
      Please direct all bug reports to /dev/null
    32. Re:Languages not for everyone by Anonymous Coward · · Score: 0

      I am forced to work on the CEO's son-in-laws 3 million+ line VB5 programs.

      Quit bitching about bad PHP. You have no idea how good those 'crap' php programmers are.

    33. Re:Languages not for everyone by digsbo · · Score: 1

      Actually, no, it [their attempt] didn't work. That's why I had to rewrite it. It crashed constantly--see my notes on performance and reliability--no system running at 80% system load is properly designed, you should generally see at least 75% user load on a cpu-saturated system.

      The mistake they made was trying to be too clever, and create a bunch of nifty framework classes that were interesting in theory but added unnecessary lines of code, genericity, and confusion. The advantage I had was that I was trying to solve a specific problem, instead of create a new framework.

      I'm not criticizing MIT grads, grad students in general, or anything like that. I'm criticizing any developer who makes things more complicated than they need to be. In this case there was a very specific problem: take some low-level i/o data and make it available to multiple clients in real time. It did not warrant 20K lines of C++; yeah, I probably seem rather stuck-up about it, but what I'm proud of is that I kept the design simple enough I could implement it properly. They were so in love with their cleverness they failed to do that.

    34. Re:Languages not for everyone by supernova_hq · · Score: 1

      So not only did he compare good PHP programmers to god, but he did so using one of the most well-known broken logical assertions known to exist?

    35. Re:Languages not for everyone by bendodge · · Score: 1

      Steve Balmer

      Wrong, because Steve Balmer doesn't exist either! You walked right into the real Steve Ballmer's trap!

      --
      The government can't save you.
    36. Re:Languages not for everyone by Anonymous Coward · · Score: 0

      Sometime perfectly good programmers must work with PHP for one reason or another.

      It's like trying to turn a gourmet meal out of convenience store groceries, though. It might taste okay but it isn't going to be quite as healthy or quite as good. One way another though, the chef matters!

    37. Re:Languages not for everyone by adamchou · · Score: 1

      so what, steve balmer still threw the chair first

    38. Re:Languages not for everyone by Anonymous Coward · · Score: 0

      You haven't contributed to Wordpress, have you? Having mucked about in there for the past couple of weeks trying to add functionality that wasn't available through plugin hooks was a serious PITA. The whole architecture of the system is FUBARed.

      Of course, I'm coming from a Scala/JavaScript/C#/Java/Ruby background. Grain of salt, and all that.

    39. Re:Languages not for everyone by Anonymous Coward · · Score: 0

      I am sorry but I have to disagree:
      nobody won because none really exist not even the chair

    40. Re:Languages not for everyone by moortak · · Score: 1

      Indeed.

      --
      Xavier Rabourdin for president 2012
    41. Re:Languages not for everyone by digsbo · · Score: 1

      Why was this modded flamebait? That's ridiculous. He's right on target: science and engineering are related, but distinct, disciplines.

      Engineering is the process of taking the outputs of science (research and development) and making it work it the real world. There is a huge difference between the personality type that can creatively solve a difficult and potential novel or unique problem and the a personality that can make that solution repeatable and low-cost in the real world.

    42. Re:Languages not for everyone by shutdown+-p+now · · Score: 1

      Granted, we tend to be outnumbered 100:1 by the PHP programmers who produce complete crap. The same is probably true of nearly any language.

      The "outnumbered" part holds true for nearly any language out there, but the precise ratio varies quite a lot. Language does matter.

    43. Re:Languages not for everyone by StikyPad · · Score: 1

      I once transformed a 2M (yes, MILLION) line project into a single line by simply replacing all instances of CR and LF with "". I'm not sure how much resources that saved, but I assume it was at least 1 million memories.

  8. Fuck CO2 by Anonymous Coward · · Score: 0

    How about we talk money instead. Apparently the cost for power and cooling is less than the cost of rewriting, at least within the planning horizon of Facebook management.

    And while we are at it, fuck C++ too. :)

  9. Sounds like cheap C-- drugs ! by redelm · · Score: 0
    ... what are you smoking???

    Yes, C-- (or even FORTRAN) is less CPU in-efficient than PHP (or most any interpreted langauge). Why do you think CPU is limiting performance and causing the high server count?

    GOOG has so many servers to be _fast_ (keep their DB in RAM). Facebook may be doing the same, or for disk.

    Can we _please_ moderate stories? This one is -1 {TROLL}.

    1. Re:Sounds like cheap C-- drugs ! by DI4BL0S · · Score: 3, Informative

      Google.com: 12,056 servers Website Worth: $ 186,352,889,952 USD (€ 126,610,389,668 EUR) Facebook: 34,872 servers Website Worth: $ 5,253,772,177 USD (€ 3,569,475,862 EUR) I'd say 'GOOG' i doing a bit better atm :) for those interested: info comes from: http://websiteshadow.com/ it will show ad rev. etc for URL's you provide

    2. Re:Sounds like cheap C-- drugs ! by peragrin · · Score: 3, Insightful

      while true it ignores things like your comparing a simple search box, with millions of users who post multi megabyte files to their personal space for everyone to see. try it some day save a facebook user's page locally and see just how much data is coming down that pipe, on top of the scripts that are running.

      Your comparing googles front door with facebooks entire company. Google probably has that many servers running web crawlers, and twice over again to store that massive database they use.

      --
      i thought once I was found, but it was only a dream.
    3. Re:Sounds like cheap C-- drugs ! by Anonymous Coward · · Score: 0

      Google does *not* have only 12K servers - I'm surprised people modded this as Informative. Estimates range from 400K to several million. Just Google it.

    4. Re:Sounds like cheap C-- drugs ! by jandoedel · · Score: 1

      that site you mention is apparently kinda unable to count correctly.
      for example, it gives 8 visitors/day for a website that i know has 4000 visitors per day.
      how does it get those numbers?

    5. Re:Sounds like cheap C-- drugs ! by BitZtream · · Score: 1

      Uhm, googles server count is in the 100's of thousands. Hell they have data centers with more than 12k servers in them.

      Of course, they do a HELL of a lot more, but thats another story.

      --
      Persistent Volume manager for Kubernetes - https://github.com/dwimsey/openshift-pvmanager
  10. 10:1... Really? by tixxit · · Score: 5, Insightful

    That's crazy. 10:1 is incredibly unfair. Especially when you consider that a cached C++ page takes just as much time to return as a cached PHP page. On top of that, majority of the work done is just searching a database. If would imagine a large part of processing a page is in getting and returning data, which is then up-to-the database. He is using stats that say PHP is 10 slower for running through loops, math that type of crap. Says nothing about querying a database then doing some minor presentation related logic. If I had to guess, for a web page the average "efficiency gain" of using C++ would be under 2x.

    1. Re:10:1... Really? by spikenerd · · Score: 0

      ...a cached C++ page takes just as much time to return as a cached PHP page...

      The 10:1 ratio refers to server load, not user experience.

    2. Re:10:1... Really? by Anonymous Coward · · Score: 1, Informative

      A cached C++-generated page takes just as much server load as a cached PHP-generated page. Better?

    3. Re:10:1... Really? by Xeriar · · Score: 2, Informative

      PHP's primary issue in the database department is it doesn't have a clean way of say, maintaining prepared statement declarations across connection instances. Which is frustrating. APC's handling of shared memory is not the best, either, and the memcached extensions for it need polish. Don't get me started on how PHP treats constants.

      Where PHP really fails, however, is in memory usage. It takes up dozens of times as much RAM as a well-built C program would. Facebook would not reduce their computer count by a factor of ten because PHP is that much less efficient at its job, but because more memory would be available in a given machine to handle more instances at once.

      Note: PHP 5.3 addresses a lot of this, but though I haven't tested it, I doubt the memory efficiency of PHP is going to get far into the double-digit percentiles of C++ in one shot.

    4. Re:10:1... Really? by Anonymous Coward · · Score: 0

      Agreed. The bottleneck for most modern webapps is database access. Database adapters are usually written in C already. In addition Apache/PHP has been standard for many years and the query/page/memory caching, load balancing, clustering, and hot-fail-over systems that work with LAMP have been extensively tested and optimized.

    5. Re:10:1... Really? by Anonymous Coward · · Score: 1, Informative

      Large websites use caching on the server side, as well as the client side.

      At the basic level, you can make sure your server side code spits out proper caching headers, and stick a caching reverse proxy in front of it (like Squid). Any page that's in the cache will be served directly out of the cache, and won't even touch the server. Even if it does, checking that the page content hasn't been changed and returning a 304 response is going to be just as fast in PHP as it is in C++ - the time taken to set up and tear down the network connection will dwarf the server code.

      Even better - you can cache pages, parts of pages, or raw data in the server application, and stick them in some kind of shared, distributed memory cache (like memcache, which Facebook use). Most of the time, the server code will be grabbing some results from the cache, sticking it in a template, and sending it to the client. Since the server code isn't doing much, it's going to be fast no matter what language it's written in.

      Worst case - you actually have to build the entire page, with data taken from the actual database. That means you need to connect to the database server, issue some SQL queries, stick the results in a template, and send that to the client. The slowest part here is unquestionably going to be the database - it hardly matters which language you're using, since you're talking to the same database server.

    6. Re:10:1... Really? by dbialac · · Score: 1

      While working at a major online brokerage, I was tasked with comparing a basic "hello world" program written in 3 methods: Perl in CGI, Perl in a core-dumped executable (this was the 90s) and C++. C++ of course won, but when you took the compile time away from Perl, the factor decreased from 8:1 to around 1.5:1. I'm guessing you'd find that PHP behaves in much the same way.

    7. Re:10:1... Really? by butlerm · · Score: 2, Informative

      In terms of total page delivery latency for a typical I/O bound application, sure. In terms of actual cpu usage, 10x overhead for any dynamically typed language is to be expected. If the application servers are CPU bound, that means a lot more servers.

      In addition, dynamic languages do not compile or JIT well, compared to statically typed languages, which severely limits the overhead reduction achievable.

    8. Re:10:1... Really? by DrXym · · Score: 1

      On top of that C++ webapps are almost certainly going to be crashier, leakier and much slower to develop than something written in PHP, Java etc.That's the reason why C++ isn't used much for web apps these days. The latency in most web apps isn't the page anyway, it's reading a file, waiting for a database to return or something else. Changing the language for marginal speed gains while taking a huge hit on reliability, uptime and the constant server recycling simply isn't an option for most companies.

    9. Re:10:1... Really? by Anonymous Coward · · Score: 1, Informative

      No. Most time is usually spent generating pages: the Wikipedia server role page shows it clearly.

      He is using stats that say PHP is 10 slower for running through loops, math that type of crap

      Yeah, statistics, they are all lies if they don't support my current opinions ;). See for yourself. PHP is between 3 to 116 times slower than C++.

    10. Re:10:1... Really? by shentino · · Score: 1

      You bring up an interesting point.

      How good are PHP-generated pages at marking themselves properly for cacheability?

    11. Re:10:1... Really? by Anonymous Coward · · Score: 0

      That's crazy. 10:1 is incredibly unfair. Especially when you consider that a cached C++ page takes just as much time to return as a cached PHP page. On top of that, majority of the work done is just searching a database. If would imagine a large part of processing a page is in getting and returning data, which is then up-to-the database. He is using stats that say PHP is 10 slower for running through loops, math that type of crap. Says nothing about querying a database then doing some minor presentation related logic. If I had to guess, for a web page the average "efficiency gain" of using C++ would be under 2x.

      The referenced facebook blog article suggests that they are not actually caching generated pages (since obviously most of them or individualized as most people are logged in), but only database queries in a big memcached layer.

      Moreover, did you know that since multi-tasking OS'es were invented some 20 (?) years ago, the kernel will switch to another process while a process is waiting for I/O? Thus even if indeed there is a lot of waiting involved in generating another process, the waiting does not consume CPU resources and is certainly not a reason to add servers...

      And since most of their servers run PHP/Apache, and they admit themselves that it is a delicate balance between lousy run time performance and ease of programming (but a nightmare to maintain), we should perhaps believe that their PHP is somewhat a bottleneck ?

    12. Re:10:1... Really? by Anonymous Coward · · Score: 0

      On top of that C++ webapps are almost certainly going to be crashier, leakier and much slower to develop than something written in PHP, Java etc.

      Not if they're developed by someone who actually knows C++.

    13. Re:10:1... Really? by Tablizer · · Score: 1

      "Hello World" hardly seems like a practical test case. Instead, perhaps make a test that queries a database for products fitting user-entered conditions and then display them.

    14. Re:10:1... Really? by DrXym · · Score: 1
      Not if they're developed by someone who actually knows C++.

      Pure baloney. Every C++ programmer in existence has experienced memory leaks, buffer overruns, pointer exceptions, stack overflows, and a raft of other issues that do not exist or exist in a more structured way in other languages. Even defensive programming techniques will not save you from them.

    15. Re:10:1... Really? by gbjbaanb · · Score: 1

      But you don't take the compile time away, just like you don't take the time it takes the developer to copy the files to the webserver or set the php config options.

    16. Re:10:1... Really? by chdig · · Score: 1

      The answer is: How good are your developers?

      Facebook has improved the php memcache extension specifically to get the most out of caching requests (and given the improvements back to the community), and since caching is their main method of reducing server load, I'd assume they're pretty good at it.

    17. Re:10:1... Really? by MikeFM · · Score: 1

      In most cases none of these issues really matter much. Most pages are cached in memory which is plenty fast regardless of the APC/Memcache issues. Most websites don't need to do anything fancy with databases and most should be caching most their data in memory. Wasted memory might be a slight issue but it rarely becomes an issue in my experience. When it does you rewrite that code in Java or Python or C. The only time this is really an issue is when doing large data crunching functions that really shouldn't be done in PHP. I'd be surprised if Facebook is doing that in PHP.

      So you're probably correct about these issues but the practical impact is small I think. I would like to see PHP sped up and use less memory but I wouldn't even consider switching to C++ because of these issues.

      --
      At what price learning? At what cost wisdom? The price is a man's peace of mind, and the cost is his life.
    18. Re:10:1... Really? by Waccoon · · Score: 1

      I don't work with JavaScript, but... what's all this fuss about new JS engines running 20-40x faster? Isn't the code just going to be slowed down by the browser and AJAX requests and stuff? Why make a big deal about an order of magnitude performance increase in the script code?

    19. Re:10:1... Really? by Anonymous Coward · · Score: 0

      While what you say is right in the case of most websites, I don't think it applies to Facebook.
      Caching doesn't magically speed everything up when the contents of the page changes extremely frequently.

    20. Re:10:1... Really? by bartwol · · Score: 1

      But you don't take the compile time away, just like you don't take the time it takes the developer to copy the files to the webserver or set the php config options.

      But with that kind of potential savings, you *can* take compile time away, very cost effectively, by installing Mod_Perl to cache compiled Perl code (and Zend Platform or others for doing the same with PHP code).

      And I do hope you're not spending much time copying files or setting your php config options. If you are, then something is amiss (you might need some well-crafted scripts and split operating environments).

    21. Re:10:1... Really? by Minimalist360 · · Score: 1

      Are you talking about C or C++?

    22. Re:10:1... Really? by damg · · Score: 1

      Yep, silly article, the CPU intensive work is already in C++; the PHP code is mostly doing I/O. C++ won't make your memory/disks/network any faster. That's why they need all those servers.

    23. Re:10:1... Really? by DrXym · · Score: 1

      Either, both. C++ can protect against some things that C can't, e.g. auto_ptr protects against objects going out of scope without being freed, but both are still more error prone than virtually all higher level languages for web app development. Even with some kind of web app framework for C++ such as wt it would still be more error prone. I'm not arguing C/C++ are obsolete or any such thing, just that every tool has it's place and C/C++ is best suited for lower level stuff. For example, if my app servers were protected by a pass through server I might well consider using an NSAPI plugin in C++ on that server that handled security, leaving the apps behind to concentrate on functionality.

    24. Re:10:1... Really? by Minimalist360 · · Score: 1
      Indeed, garbage collection is a wonderful thing.

      like you're stating, sometimes it truly is the best solution to have multiple technologies in place, as long as they're smartly used. If not, you end up with a maintenance nightmare.

      Amazon.com is a great success story and an example of using different technologies well, and it came about because they got their architecture correct. It started as a single C++ app talking to a backend, and that wasn't really going to scale well. I've heard that a single page on Amazong.com might talk to 100+ different services. In some places they use java servlets, in others they use Perl/Mason.

      I've seen smaller companies with hybrid systems due to evolution or the top-down "we need to recode this but don't have a full budget." They tend to have real problems and the technology drags down the rest of the business. In a team of 5 people, it's hard to hire when you have 2-3 different technologies. When you're larger that's less of an issue, as you can have people devoted to an area of your software pile that is in the language or set of technologies they are good at.

    25. Re:10:1... Really? by Anonymous Coward · · Score: 0

      Quick question, what is a cached C++ page?

      The rest of your post was ignored.

    26. Re:10:1... Really? by ZerdZerd · · Score: 1

      Exactly. Most of the time is spent waiting on I/O anyway!

      --
      I'm not insane! My mother had me tested.
  11. tax them! by Anonymous Coward · · Score: 0

    I think they should be charged a 10% pollution tax for every server above the amount needed by C++ code.

  12. First post from TFA nails it by hilather · · Score: 2, Informative

    Read the first posters points (in TFA) he pretty much sums everything up.

  13. The REAL solution by DoofusOfDeath · · Score: 5, Funny

    Just serve up plain text files. Anything else is pure decadence!

    1. Re:The REAL solution by Anonymous Coward · · Score: 1, Funny

      I agree. We can receive said text files via hand signals from the tree tops, to which we will have climbed back up after eschewing all technology to minimize our collective carbon footprints.

    2. Re:The REAL solution by Anonymous Coward · · Score: 0

      And capitalize on those default browser styles. I pine away for Times New Roman on the Web, and that bland Netscape gray from 1996 always drabbbed my day.

    3. Re:The REAL solution by arndawg · · Score: 1

      I'm hearing faxing is pretty hot these days.

    4. Re:The REAL solution by maxwell+demon · · Score: 1

      No, no, no, you're doing it wrong. Climbing into trees will increase your CO2 output. Stay on the floor!

      --
      The Tao of math: The numbers you can count are not the real numbers.
    5. Re:The REAL solution by bigngamer92 · · Score: 1

      The next day Doofus received an e-mail reading:

      Hey! I've just added pictures to my profile page! You should sign up for facebook to view my pics now!

      img="drinking tequila on the beach"
      img="goatse"
      img="my wedding to a moose"
      img="russia, seen from my house"
      link=www.facerbook.com/spam/malware/download

      p.s. I don't know the real way that facebook emails are set up or how to put html code into slashdot. Just imagine that it was in proper HTML :p

    6. Re:The REAL solution by adamchou · · Score: 1

      well, technically, an html page is just a plain text file

  14. where did he get this factor? by quickOnTheUptake · · Score: 5, Insightful

    I'm thinking that these scripts are just thin front ends to a massive db. Thus, a lot of the computer's time is going to be spent on I/O, and a lot of the processing is going to be taking place in the db itself, which is probably written in C.

    --
    Mod points: Guaranteed to remove your sense of humor.
    Side effects may include gullibility and temporary retardation
    1. Re:where did he get this factor? by betterunixthanunix · · Score: 1

      What you said might have been true 10 years ago, before all this AJAX code. When you have millions of users pumping out AJAX requests, your middleware is going to wind up working a lot harder, and the database is still doing all the things it was doing back in the 90s.

      --
      Palm trees and 8
    2. Re:where did he get this factor? by cybiko123 · · Score: 3, Informative

      OK, let's say AJAX didn't exist for a moment. People would have to refresh their browsers to display/submit forms, which would require Apache/PHP to serve a *full web page* for every form displayed and submitted. This in itself causes a load on servers, before dynamic content is even considered. If anything, AJAX *lowers* server load.

    3. Re:where did he get this factor? by betterunixthanunix · · Score: 1

      "OK, let's say AJAX didn't exist for a moment."

      In other words, look at how things were done back in the 90s.

      "People would have to refresh their browsers to display/submit forms,"

      Why would you need to refresh your browser to submit a form? You enter your form data, and you hit the submit button, and everything is good to go. No muss, no fuss, and no need to send request after request to your server -- two are sufficient (one to get the form, one to submit the form). Considering that a lot of website use does not even involve form submission, you can save even more -- one request per page is entirely sufficient.

      "which would require Apache/PHP to serve a *full web page* for every form displayed and submitted."

      Serving a full web page is not a terrible strain; in fact, for static content, it can be highly efficient. A while back, Slashdot ran a story about the servers that run Slashdot itself; the majority were serving static content that was pregenerated and refreshed every so often, and only those users who absolutely required dynamic content (such as those submitting a comment) would be served by the dynamic server. I have seen many websites that are linked to from Slashdot switch to static content just to handle the load (a tactic that is successful in some cases).

      "This in itself causes a load on servers, before dynamic content is even considered."

      Load which is unavoidable even with AJAX. The AJAX code itself must be sent, at the very least, as well as the various UI elements and CSS that are necessary with AJAX -- all of which is still being served like a static page. This is not factoring in any dynamic content that is sent along with that code, which is almost always present, and all this has to happen before any of the AJAX code actually does anything.

      You might say that the AJAX code reduces the overall overhead, because it lowers the amount of dynamic content that must be generated. This might be true in a few cases, particularly those where the data is constantly being fed and where there is only one page of interest (think stock market data), but I would be very wary of any assertion that AJAX lowers overhead on a website like Facebook, where the users frequently browse to different pages (different profiles) and where various AJAX applications follow them around (instant messenger, etc.).

      "If anything, AJAX *lowers* server load."

      The funny thing is that in most cases where I have heard of AJAX causing a significantly lower overhead, the problem has been the use of HTTP itself -- other protocols are inherently more efficient for those tasks. AJAX makes web pages look nicer (in some cases) and feel more like desktop applications, but I would not claim that it reduces server loads except in a few niche cases.

      --
      Palm trees and 8
    4. Re:where did he get this factor? by Anonymous Coward · · Score: 0

      I definitely agree here. I started converting an internal at work to using AJAX and the server load went down a huge magnitude (processor was always pegged at 100% and after the conversion it had idle cycles).
      After that experiment, we converted the rest of the project to AJAX and it enhanced the user-experience and reduced server load as we didn't have to retransmit things the client already had.

    5. Re:where did he get this factor? by Anonymous Coward · · Score: 0

      Are you sure about that?

      Ajax lets you return little bits of info, which you can update on the page using Javascript. I would in fact argue the exact opposite, with all this Ajax on pages (and Javascript sorting the presentation) your PHP is going to be fairly lightweight conduit to the database, just taking info from a database and spitting out XML or JSON. I'd be surprised if there was much difference between any language doing that on the web today, it's pretty much the most basic thing you're doing when you generate every page and a pretty obvious place to look for efficiency improvements.

    6. Re:where did he get this factor? by Anonymous Coward · · Score: 0

      OK, let's say AJAX didn't exist for a moment. People would have to refresh their browsers to display/submit forms, which would require Apache/PHP to serve a *full web page* for every form displayed and submitted. This in itself causes a load on servers, before dynamic content is even considered.

      If anything, AJAX *lowers* server load.

      But it increases the load of the client PCs. My AMD Thunderbird machine from 2000 rendered ten static pages in the time it takes my Core 2 Duo machine to update one Facebook page.

    7. Re:where did he get this factor? by quickOnTheUptake · · Score: 3, Insightful
      Honestly WTF are you talking about? AJAX moves rendering/layout of dynamic content to the client. Ergo, it is going to reduce the processing necessary on the server to do any given job.
      I could copy and paste each paragraph of your post followed by some comment to the effect I have no idea how the paragraph is relevant, but I will spare the readers and just pick a couple general points of confusion.
      You seem to confuse static (plain html, something that does not enter into the conversation _at_ _all_) with server generated (precisely the sort of thing PHP is used for). E.g.,

      in fact, for static content, it can be highly efficient. . . . the majority were serving static content that was pregenerated and refreshed every so often

      Again, no one is talking about static content, including GP who was talking about forms, and server generated pages.
      You also seem to be confused about the general load on the server (factoring in thing like total MB served or something) as opposed to precisely the CPU load (again this is what we are talking about: no one cares about the fact that more complex web sites need CSS and JS files served up). E.g.,

      The AJAX code itself must be sent, at the very least, as well as the various UI elements and CSS that are necessary with AJAX -- all of which is still being served like a static page.

      --
      Mod points: Guaranteed to remove your sense of humor.
      Side effects may include gullibility and temporary retardation
    8. Re:where did he get this factor? by Tablizer · · Score: 1

      AJAX moves rendering/layout of dynamic content to the client. Ergo, it is going to reduce the processing necessary on the server to do any given job.

      But remember that this article is about saving polar bears, not server cycles. Busy clients will still consume resources. However, perhaps much of that CPU would be idle anyhow on the client. The calculations are becoming more involved.
           

    9. Re:where did he get this factor? by skeeto · · Score: 1

      Yeah, TFA is total bullshit. The PHP scripts probably spend 99% of their time waiting on the network or on a database query. Rewriting in C++ would have virtually no gains, but development/maintenance effort would shoot way up.

    10. Re:where did he get this factor? by Anonymous Coward · · Score: 0

      If anything, ajax and other client side schemes that transports functionality to the client end of the deal are the worst polluters of them all.
      Not only the transport cost of the data but also the inefficient execution of ajax overhead.

      It does not matter where the damage is done.

    11. Re:where did he get this factor? by Anonymous Coward · · Score: 0

      And then, how does moving all that work to the client reduces the overall energy comsumption?

      As home computers aren't very energy efficient, I'm guessing that is even worse...

    12. Re:where did he get this factor? by Lambeco · · Score: 1

      I try so hard not to be "that guy", but when did people start using the word AJAX when they mean DHTML? Or when did that become acceptable? AJAX is about asynchronous communication between web client and server; it has nothing to do with manipulating the DOM, which is what DHTML is for. I can understand the desire to lump the two together because they tend to go hand in hand, but when you say something like "AJAX moves rendering/layout of dynamic content to the client," you couldn't be any more wrong. Rendering and layout is handled via DHTML.

    13. Re:where did he get this factor? by Lambeco · · Score: 1

      After rereading your post, I realized what you meant by moving rendering/layout to the client. I misinterpreted, so I apologize.

  15. No. by A+Friendly+Troll · · Score: 5, Insightful

    Simply put: no.

    The reason why they have so many servers is because Facebook contains so much data. The servers are there for a reason, and the reason is CACHING.

    The overhead of PHP is very small for a platform that is all about sharing data and the bulk of processor time surely goes towards fetching that data in the first place. What, do you seriously think that when you hit your home page on Facebook, there are database queries issued for that? Lulz.

    Besides, I'm almost sure that FB uses something like Zend Accelerator, which increases code execution speed a lot.

    Anyway, just no.

    1. Re:No. by moz25 · · Score: 2, Informative

      Very true: they are are big contributor to projects like memcache.

    2. Re:No. by Anonymous Coward · · Score: 2, Informative

      MemCache.

      Last time I read about Facebook (2008), they had 800+ machines running memcache, providing somewhere in the region of 28 TB of total memory.

      Then the databases is shared across thousands of database servers.

      I think our C++ friend is rapidly running out of servers to run his efficient C++ on....

    3. Re:No. by Anonymous Coward · · Score: 0

      Scripting languages have their place. Quick and dirty and fast dev time. The trade off here is speed of development and number of servers. I doubt it is is 10 to 1 as the article claims (probably much less).

      Having written projects that are structurally the same in different languages I can tell you C runs circles around the 4gl langs on the same processor. Now this is probably not a fair comparison as we deliberately did not use the strengths of any language to remain 'portable'. The down side is maintenance in C is rather high (watching for over runs and leaks). But size and speed smoke the 4gl langs (python, php, java, c#, etc...). Now these langs do run 'decently' in most cases. But when they run off the rails they do it rather spectacularly I have seen cases as much as 200x slower.

      If I need 2 extra servers its not that big of a deal. But if I need extra thousands servers the trade off becomes a bit easier to make the dev fix it.

      Now in the article (which looks like a slashvertisment for wt) most of those servers are for memory storage, load balance, and caching. They have huge portions of data cached and 'ready to go' and somewhat close to the users. This is the trade off they have made. They want quick render and ease of development. So they are throwing more hardware at the problem and they are willing to pay for it.

      As one manger put it to me 'efficient code is great but if it takes you two months to do it, it costs me 8-10k, plus the testers time. I can buy 3-6 servers for that and just leverage us out of the problem with more hardware. Oh in the mean time you are not creating a new thing you are just reworking something we already have.' Is this the right thing to do? Not always. But many times yes. In MBA speak it is opportunity cost.

    4. Re:No. by Anonymous Coward · · Score: 0

      According to the first link in the article (from Facebook), the bulk of the 30000 servers is dedicated to running PHP/Apache. That seems in line with 800+ servers runing memcached, and a few thousands (4000 ?) servers?

    5. Re:No. by A+Friendly+Troll · · Score: 1

      According to the first link in the article (from Facebook), the bulk of the 30000 servers is dedicated to running PHP/Apache. That seems in line with 800+ servers runing memcached, and a few thousands (4000 ?) servers?

      The bulk of those 30k servers is probably also running a partitioned database, which - as you may have guessed - is also cached in memory. It's cache one way or another. Now, if they have 25k pure PHP servers, 4k pure DB servers, and 1k pure memcached servers, that's a different issue, but I don't think that would be the case...

    6. Re:No. by Anonymous Coward · · Score: 0

      Well, they are running 30000 servers, so let's do some math. 30000 - 800 - few thousands =~ 25000 ?

      Hey that would actually be in line with Facebook stating "The majority of our servers are web servers running PHP" !

    7. Re:No. by dcw3 · · Score: 1

      The reason why they have so many servers is because Facebook contains so much data. The servers are there for a reason, and the reason is.....KAH-CHING.

      Fixed that last word for ya.

      --
      Just another day in Paradise
    8. Re:No. by gatesvp · · Score: 1

      I'll add to this comment, FTA:

      Back-end services that require the performance are implemente in C++.

      And most of these 30k servers may be "running" PHP, but goodness their code is not all PHP. Facebook leverages a large amount of open source software and it's definitely not all PHP. MySQL isn't PHP, MemcacheD isn't PHP, Cassandra & Hive are written in Java, Thrift and Scribe are built in C++.

      This guy's whole premise is completely under-researched, to tell people at Facebook that they're missing a 10:1 performance opportunity b/c of PHP is pretty ridiculous.

  16. Please by Anonymous Coward · · Score: 2, Informative

    I don't care about your environmentalism.

    1. Re:Please by AnotherShep · · Score: 4, Informative

      Even better, TFA is a page for a C++ web toolkit. It's just spam.

    2. Re:Please by Anonymous Coward · · Score: 0

      Indeed. C++ is a poor language to compare against. Java or .NET would be more valid comparison, where you get the speed of development and good programming environments, as well as pretty good execution speeds (not too far off C++ in both cases).

      If the same amount of effort went into PHP compilers/JIT as went into Javascript JITs then we could have a different situation entirely.

    3. Re:Please by Lord+Kano · · Score: 1

      Except of course that .NET isn't a "language".

      LK

      --
      "Hi. This is my friend, Jack Shit, and you don't know him." - Lord Kano
  17. Why stop there? by Freestonepilgrim · · Score: 5, Insightful

    Why not rewrite everything in assembly? This comparison comes to a conclusion without any facts to back it up. As others have pointed out there is development time and compile time associated with C++... and what about ongoing development? Where does 10-1 come from? Are you assuming they aren't doing any optimization or using any sort of accelerator? I've personally re-written code in C++ from php, and then done the comparison. In our case, we decided the extra maintainability was worth the approx 10-20% increase in speed we saw.

    1. Re:Why stop there? by luzr · · Score: 1
      Because C++ is faster?

      Seriously, if you take into account templates and inlining, there is a good chance that moderately good C++ code will run faster than moderately good assembly, on x86-64 of course - simply because assembler coder would not have the patience to take all opportunities of inlining.

    2. Re:Why stop there? by hackstraw · · Score: 1

      Why stop there. FPGAs FTW!!!

    3. Re:Why stop there? by mukund · · Score: 1

      Full custom CMOS VLSI circuits are more efficient :)

      On the other hand, you could simply pick up the phone and call your friends :)

      --
      Banu
    4. Re:Why stop there? by dkf · · Score: 2, Insightful

      Seriously, if you take into account templates and inlining, there is a good chance that moderately good C++ code will run faster than moderately good assembly, on x86-64 of course - simply because assembler coder would not have the patience to take all opportunities of inlining.

      You might think so, but it's not as simple as all that. You also have to take into account the CPU's caching behavior; large numbers of inlines can (i.e., I've seen it happen) make the size of the working set too large to fit in L1 (or even L2) cache. That in turn means that you're taking a substantial performance hit. What's better, the size of those caches is dependent on exactly what sort of processor you're working with, so compilers don't take them into account.

      Inlining is a trade-off, as it increases the size of the object code in return for removing the cost of a function call. (It's also total poison for any ABI which needs long-term version management, since it effectively bakes internal details of the called objects into the callers' code, even if not at the source level. But I'm digressing) And yet modern CPUs have pretty decent branch predictors, and so the costs of a function call are often very low to almost non-existent...

      --
      "Little does he know, but there is no 'I' in 'Idiot'!"
    5. Re:Why stop there? by wtbname · · Score: 1

      MOV Ashley, Enemies
      MOV Jill, Friends
      DIV Enemies, Lies
      ADD CurrentMusic
      ADD FeelingGood
      MOV Jill, Enemies

    6. Re:Why stop there? by luzr · · Score: 1

      Seriously, if you take into account templates and inlining, there is a good chance that moderately good C++ code will run faster than moderately good assembly, on x86-64 of course - simply because assembler coder would not have the patience to take all opportunities of inlining.

      You might think so, but it's not as simple as all that. You also have to take into account the CPU's caching behavior; large numbers of inlines can (i.e., I've seen it happen) make the size of the working set too large to fit in L1 (or even L2) cache.

      Correct, but it does not change the premise. Actually, all major C++ compilers are well aware about the situation and are very good at optimizing inlines (and not optimizing when it does not make sense).

      In fact, what really counts is not inlining itself, but optimization across multiple functions call - in C++, multiple calls can get collapsed into a couple of assembly instructions. Often, such collapsing leads into less code bytes than required to perform function call.

      BTW, branch prediction does not have anything to do with unconditional procedure calls. Branch prediction is about conditional jumps. That said, yes, modern CPUs are pretty good at about everything.

    7. Re:Why stop there? by Anonymous Coward · · Score: 0

      what friends?

    8. Re:Why stop there? by butlerm · · Score: 1

      10:1 is a conservative estimate of the *efficiency* of page generation in PHP vs. C++. If you are not CPU bound on the page generation servers, an increase in page generation efficiency won't make a perceptible difference.

      However, if you have a large number of servers that do nothing other than page generation because the page generation process is CPU bound, how efficient that process is makes a big difference in terms of how many servers you require. So small sites shouldn't care, and very large sites should care *a lot*.

    9. Re:Why stop there? by wik · · Score: 1

      Minor nit: fetch prediction logic in modern processors has to deal with unconditional procedure calls. Fetch pipelines aren't shallow anymore, so you need to predict the target address and speculatively fetch that cache line. Often this is before you even know you've just fetched a branch/call/jmpl.

      The jump tables/switch statements in Ruby/Python/PHP make target prediction a necessity. The target of this jmpl is rarely the same twice in a row.

      --
      / \
      \ / ASCII ribbon campaign for peace
      x
      / \
    10. Re:Why stop there? by BitZtream · · Score: 1

      Since I'm not actually aware of any CPU that natively runs PHP code, I'm going to have to just assume that you don't realize that PHP code gets compiled as well, everytime you run it? Okay, so if you have a proper caching engine on your PHP servers than it only gets compiled when its changed ... which interestingly enough, only then makes it just the same as a C app, not better.

      'Extra maintainability' translates into lack of development skills on your part, sorry. If you're doing anything different while developing PHP code than you would do for C or C++ then you aren't following a proper development path, you aren't actually a professional developer, you're just hacking scripts.

      --
      Persistent Volume manager for Kubernetes - https://github.com/dwimsey/openshift-pvmanager
    11. Re:Why stop there? by luzr · · Score: 1
      OK, you are correct that unconditional but indirect procedure calls (where target address is not a constant) are wholy different kind of beast.

      But that, as you correctly conlude, in C++ affects mainly switch statements or inter-shared library (or dll) calls and has little to do with inlines.

    12. Re:Why stop there? by dkf · · Score: 1

      Correct, but it does not change the premise. Actually, all major C++ compilers are well aware about the situation and are very good at optimizing inlines (and not optimizing when it does not make sense).

      They can only really do a good job if they're taking into account the size of the caches, and that's not portable at all. A lot of people don't have the luxury of only ever coding for one processor variant. (Curiously, I work somewhere where that level of optimization is sometimes used for real. But we tend to not use it for C++, reserving it for key Fortran libraries only.)

      In fact, what really counts is not inlining itself, but optimization across multiple functions call - in C++, multiple calls can get collapsed into a couple of assembly instructions. Often, such collapsing leads into less code bytes than required to perform function call.

      It critically depends on the details, since the real overall win comes when you get to fit everything in a level of cache that is closer to the CPU than before; L1 beats L2 beats memory beats disk (i.e. paged out). If you're only inlining trivial accessors then you're correct, but that's not the only case that people inline. For something longer, it's a much trickier tradeoff. (And inlines have that ABI-bake-in problem which you ignored, which really bites in production libraries. Mainline developers don't see the issue, but maintenance programmers and deployment engineers do.)

      BTW, branch prediction does not have anything to do with unconditional procedure calls. Branch prediction is about conditional jumps. That said, yes, modern CPUs are pretty good at about everything.

      Actually, branch prediction is also about unconditional jumps. They just happen to be a very easy case.

      --
      "Little does he know, but there is no 'I' in 'Idiot'!"
    13. Re:Why stop there? by pclminion · · Score: 1

      As others have pointed out there is development time and compile time associated with C++

      Why does compile time matter? How much time is spent compiling vs. testing? At my company, building the product core takes 7.5 minutes. Putting it through the full set of release-gating tests takes, on average, about three weeks.

      Or are you saying you don't test your code? In my experience, people who tout the lack of compilation as an advantage tend to be the same people who throw code into production without even basic testing.

    14. Re:Why stop there? by Anonymous Coward · · Score: 0

      These days it's really quite difficult to hand code assembly that's more efficient than compiled, optimized C++ code.

    15. Re:Why stop there? by El_Muerte_TDS · · Score: 1

      Assembly? please.

      Rewrite everything with butterflies.

    16. Re:Why stop there? by luzr · · Score: 1

      Correct, but it does not change the premise. Actually, all major C++ compilers are well aware about the situation and are very good at optimizing inlines (and not optimizing when it does not make sense).

      They can only really do a good job if they're taking into account the size of the caches, and that's not portable at all. A lot of people don't have the luxury of only ever coding for one processor variant.

      First, in real modern CPUs _practical_ differences are not that big. E.g., put the inlining limit to 32 bytes (for fast code) and you will hardly see performance degradation anywhere.

      But the main issue: inlining often leads to code that is actually shorter than the call.

      (Curiously, I work somewhere where that level of optimization is sometimes used for real.

      So do I. I have spent years optimizing stuff in C++. Benchmarking and examining produced assembly is my second nature. That is why I am pretty sure I could not achieve C++ levels in any other language, assembler included.

      In fact, what really counts is not inlining itself, but optimization across multiple functions call - in C++, multiple calls can get collapsed into a couple of assembly instructions. Often, such collapsing leads into less code bytes than required to perform function call.

      If you're only inlining trivial accessors then you're correct, but that's not the only case that people inline. For something longer, it's a much trickier tradeoff.

      Specifically, in my C++ code, String comparison inlined fast path collapses to 5 assembler opcodes. That is about as long as function call.

      And I would not call String comparison trivial accessor.

      But even so, the problem of even trivial accessors is that they often tend to go deep. In container intense code, without inlines, you might end spending 50% of time just managing stack frames for element retrieval calls.

      (And inlines have that ABI-bake-in problem which you ignored, which really bites in production libraries. Mainline developers don't see the issue, but maintenance programmers and deployment engineers do.)

      No dispute there, there is a big problem with C++ and maintaining shared library compatibility.

      For most applications it can be easily solved by not using shared libraries... Facebook would be a nice example. After all, PHP does not produce .so libraries as well...

    17. Re:Why stop there? by RzUpAnmsCwrds · · Score: 1

      Inlining is a trade-off, as it increases the size of the object code in return for removing the cost of a function call.

      The big thing that inlining does, like many compiler optimizations (including things like loop unrolling) is to expose opportunities for additional optimization.

      And, FYI good compilers do support multiple architecture versions, and some (ICC) will even generate multiple code paths and code to select the right one at runtime.

      This doesn't excuse you from understanding the architecture (particularly the memory hierarchy). Your compiler generally can't make your random memory accesses sequential (unless you get really lucky with optimizations), nor can it turn bubble sort into something efficient.

      But you can get within 10% of hand-optimized assembly code in most cases, with a good compiler. And you can do it with vastly lower developer cost.

    18. Re:Why stop there? by alexo · · Score: 1

      Rewrite everything with butterflies.

      As an added bonus, it will be easier to debug.

  18. Just think how much greener they could be... by John+Hasler · · Score: 1, Funny

    ...were they to rewrite it all in assembly language!

    --
    Warning: this article may contain humor, sarcasm, parody, and perhaps even irony. Read at your own risk.
    1. Re:Just think how much greener they could be... by gander666 · · Score: 1

      Dang whippersnappers, Everything should be written in Assembly. Dag nabbit. I learnt Assembly (gasp - 6502 and PDP Macro 11) I think that the new fangled macro assemblers should be enough for anyone!

      Seriously, use the best tool for the job, and move on. Nothing to see here...

      --
      Suppose you were an idiot and suppose you were a member of Congress ... but I repeat myself. - Mark T
    2. Re:Just think how much greener they could be... by tepples · · Score: 1

      I learnt Assembly (gasp - 6502 and PDP Macro 11)

      And I still use 6502 assembly to make NES games because I've never seen a compiler that can make use of its three internal registers and 256 RAM registers even half as efficiently as hand-coded asm can. But as for PDP-11, its macro-assembly language is called C.

    3. Re:Just think how much greener they could be... by mehrotra.akash · · Score: 1

      why stop at assembly, use machine language

  19. Interpreted Languages... by zippthorne · · Score: 2, Insightful

    For something that is deployed to tens of thousands of machines..

    Is there some reason why these languages couldn't be compiled and optimized? Code is just the programmer's will expressed as text that the machine can somehow interpret, right? If there is so much PHP out there, why wouldn't/couldn't there be an efficient compiler (by which I mean something that produces executables and not just "executables that are really just an interpreter tacked onto a script")

    The dearth of such compilers on the market suggests to me that the gains wouldn't be as great as claimed for the majority of applications where interpreted languages are used.

    --
    Can you be Even More Awesome?!
    1. Re:Interpreted Languages... by cryfreedomlove · · Score: 1

      Is there some reason why these languages couldn't be compiled and optimized?

      Java is another language that has been knocked around for years by C++ puritans but it has, in fact, become very well compiled and optimized.

    2. Re:Interpreted Languages... by djmurdoch · · Score: 1

      I've no idea about PHP, but the usual problem with interpreted languages is that their model of the computer is too high level to be a good match to the hardware. To compile to fast code, the operations being performed need to map predictably to machine instructions. If the same a+b line could, depending on what preceded it, mean adding integers, adding floating point values, or concatenating strings, then it's not going to compile to anything as fast as a statically typed language where it might be one or two machine instructions.

    3. Re:Interpreted Languages... by Virak · · Score: 1

      Because highly dynamic languages that do everything at runtime are not so easy to optimize at compile time. It is possible though to do all sorts of fancy things at runtime, such as with, for example, Java (though ironically Java is the exact opposite of this sort of language and doesn't really need it so much), and some traditionally purely interpreted languages like JavaScript have started getting snazzy JIT implementations these days. PHP wouldn't benefit from this sort of stuff too much as it's largely IO-bound in practice, and, as a few other users here have noted, most of the heavy lifting in PHP applications is done in databases which are most certainly not written in this sort of language.

    4. Re:Interpreted Languages... by Anonymous Coward · · Score: 0, Flamebait

      Java is another language that has been knocked around for years by C++ puritans but it has, in fact, become very well compiled and optimized.

      Yes yes, very nice. Now make the language not shit, please.

    5. Re:Interpreted Languages... by FooAtWFU · · Score: 3, Informative
      A lot of the power of interpreted languages comes from the abstractions that are put in place to make programming easier. These abstractions have a price in terms of execution time. Furthermore, once you're using an abstraction, there's not a simple way in the imperative paradigm for a compiler to determine that your code needs XYZ part of the abstraction, but not part ABC. You need to do the whole thing.

      For example, consider the following. Say bad things about PHP all you want (it deserves it) but one of the things you don't generally see with PHP code is a buffer overflow, where you try to copy a bunch of strings and concatenate them together and you run out of room and don't notice it and you go clobbering memory. That's because the string manipulation code goes through a bunch of checks when you're appending strings. You can't just skip these checks and hope that everything will work the same. You may know that such and such a code-path isn't going to need all the bounds checking because you're, say, idunno, assembling fixed-length ZIP+4 codes or something, but the scripting language can't be informed of that fact using any extant mechanism (nor is it clear how you could integrate such a mechanism with the powerful abstraction that lets you not worry about the rest of your strings to begin with).

      Moreover, as has already been pointed out, a lot of the computational price of rendering a web page is database queries and memory-cached-object queries which employ compiled code already. The string-manipulation overhead isn't all that significant compared to the abstraction that it buys you. It's probably a better idea to track down logic issues, where your code does stupid useless computations that it doesn't need that make it slow, or could do certain computations in advance to make it faster, or such.

      I think there's a lot more potential for interesting machine optimization of code for things coming from the functional paradigm, where you can mathematically show the equivalence of certain portions of code with its optimized replacement, and that this paradigm will be making a resurgence in some places during the upcoming era of 128-core processors. This might be interesting.

      --
      The World Wide Web is dying. Soon, we shall have only the Internet.
    6. Re:Interpreted Languages... by mebrahim · · Score: 1

      Dynamic languages are not as compilable as static ones. They are at best compiled into an intermediate form (usually called bytecode) which is run by some virtual machine. I guess PHP accelerators work this way.

    7. Re:Interpreted Languages... by musicalmicah · · Score: 5, Informative

      Actually, Facebook uses APC to compile and optimize the code in the shared memory so it doesn't have to be compiled over and over again.

      There are other libraries for caching PHP functions on many different levels as well, and they're open source, for the most part. Some real bright minds from Facebook and other large PHP applications have contributed to them.

      Bottom line: PHP is quite powerful and efficient when built and extended properly.

    8. Re:Interpreted Languages... by swillden · · Score: 1

      For example, consider the following. Say bad things about PHP all you want (it deserves it) but one of the things you don't generally see with PHP code is a buffer overflow, where you try to copy a bunch of strings and concatenate them together and you run out of room and don't notice it and you go clobbering memory. That's because the string manipulation code goes through a bunch of checks when you're appending strings. You can't just skip these checks and hope that everything will work the same.

      Of course, the same is true of the C++ std::string class.

      Not that your point is wrong, but you chose a poor example.

      --
      Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
    9. Re:Interpreted Languages... by calzones · · Score: 1

      I would think that with all the common routines being used in php all the time, it should be fairly easy to make a compiler whose job is too simply reorganize php code so that commonality is centralized within an efficient executable and the customized overhead is tacked on as an extension.

      There could even be conventions that seasoned php programmers follow to make their code more compiler friendly. Even better, if there is a way for a senior programmer to come in after the fact to make something a junior programmer wrote last year into something more compiler-friendly. This gives you all the advantages of rapid development while granting you the ability to come back later and tighten things up when you have more time or resources.

      At the minimum however, this ideal "compiler" would still make just about any php code at least about 20% more efficient. Not 1000% times more efficient, but every little bit helps.

      Throw caching on top of the pile, especially database caching, routine caching, page component caching, whole page caching, and browser caching, and you'd end up with something pretty comparable to a site written in C++.

      The advantage of php is that it frees up developers to do other stuff. Sure they're still all polluting the environment in their cars regardless of whether they're developing facebook or something else, but the best thing is ALWAYS to reduce the human input required to produce something. Eventually robots will be greener than humans at production. Let the humans go find new ways to do new things. Free up those resources to find ways to reduce emissions elsewhere, or to do something charitable, or to invent something that makes society better off and more efficient using less paper or less delivery fuel or less disposable trash associated with eating take out, or to work form home instead of having to be in cubes next to the other developers figuring out why something isn't the way it should be and getting screamed at by some UI / Marketing guy that their code is just not meeting the needs.

      Point is, sure, let's find a way to make running code more energy efficient. The way to do that is not to demonize PHP because C++ has its own inefficiencies and there's no reliable way to draw a real-world full impact comparison between the two. Maybe Facebook would never have gotten off the ground if they used C++ and it's impossible to tell what the long term environmental impact of a facebookless world is vs one with it. It's lunacy to even try.

      So we recognize there's en energy efficiency problem that can be solved. We're using PHP so that frees up resources to figure out how to be more energy efficient. Either at Facebook, or at Zend, or wherever. Tying up extra resources trying to keep Facebook running ain't the way though. And as pointed out by many others, it's the database stupid. The energy efficiencies between C++ and PHP for running facebook do exist and may even be significant, but they are not 10 to 1, and that's only a small part of the energy story.

      --
      Asking people to think is like asking them to buy you a new car
    10. Re:Interpreted Languages... by calzones · · Score: 1

      I should point out that computer component manufacturers are constantly working to make their products more efficient.

      That's the big fish here.

      Saying use C++ instead of PHP is like saying you should figure out your life so that you only drive out to the market once a week and you carpool with all your neighbors (or take orders from them to bring it back with you), and when you do it, you make sure it's at a time when there will be no traffic and the lights will all be in your favor and your tires are at the perfect pressure and you and your neighbors have figured out all your other errands and planned the most energy efficient route needed to stop at each place necessary to complete the errand after having run an energy-optimization analysis of whether to go to CVS or Walgreens. And the whole time, the decision driver is energy efficiency. Not price paid. Not time spent. Not convenience. Not quality of life.

      Seems to me the better way to deal with it is to be reasonably aware of your energy use and avoid being wantonly wasteful, and as a society to keep figuring out ways to make vehicles and neighborhood plans more efficient, and less polluting.

      --
      Asking people to think is like asking them to buy you a new car
    11. Re:Interpreted Languages... by PietjeJantje · · Score: 1

      Mod parent up. High traffic sites are not interpreted on the fly over and over again. I would be very surprised if the cost of building and maintaining a high traffic php site with the proper optimizations would cost more than doing the same thing with c++ programmers. How many more man hours, the cost of a man hour, the cost of a server, etc.

    12. Re:Interpreted Languages... by porneL · · Score: 1

      > If there is so much PHP out there, why wouldn't/couldn't there be an efficient compiler

      There is PHC and Roadsend.

      However there are PHP-specific problems that make it harder than it should be.

      PHP's "standard library" is heavily dependent on the interpreter, so you either lug it around and maintain its state, or rewrite 5000 methods.

      And there's of course eval(), extract(), dynamic include/autoload and other magic that makes static analysis pretty hard or impossible.

    13. Re:Interpreted Languages... by BitZtream · · Score: 1

      There is. www.zend.com

      With a proper webserver setup, your PHP only gets compiled the first time its viewed after a change, taking a good chunk of the load of most PHP scripts out of the picture.

      http://en.wikipedia.org/wiki/PHP_accelerator

      --
      Persistent Volume manager for Kubernetes - https://github.com/dwimsey/openshift-pvmanager
    14. Re:Interpreted Languages... by mcrbids · · Score: 1

      one of the things you don't generally see with PHP code is a buffer overflow, where you try to copy a bunch of strings and concatenate them together and you run out of room and don't notice it and you go clobbering memory. That's because the string manipulation code goes through a bunch of checks when you're appending strings.

      And this is one of the great ironies of PHP... while there *have* been a number of vulnerabilities in PHP-based applications, that's more an artifact of the unqualified developers that the language's ease-of-use tends to attract.

      PHP offers quite an impressive number of security-related features that make horrible, difficult-to-solve security problems almost a non-issue. PP example of string appending is but one of far too many to name, yet it's one that's the cause of the vast majority of security issues in software, everywhere!

      What's that, you say? The #1 cause of security issues has been all-but-eliminated in a programming language that's often chided for security issues? Doesn't really make sense, does it?

      And then, on to what is perhaps the #1 cause of security issues for database-driven product - the dreaded SQL injection error. Yep, that one has been solved too!

      Yes, you can use PHP to write an insecure application. But you can use an SUV with seat belts and airbags to kill yourself, too. When discussing security, PHP doesn't get anywhere near the respect it otherwise deserves.

      --
      I have no problem with your religion until you decide it's reason to deprive others of the truth.
    15. Re:Interpreted Languages... by butlerm · · Score: 1

      High traffic sites are not interpreted on the fly over and over again

      Substitute "parsed" for "interpreted" and I agree 100%. There are plenty of high traffic sites that don't JIT every last bit of code, however, and are most definitely interpreted for everything that is not compiled to native code. Sites that use JVMs are typical.

      However, I am shocked that special effort is required for PHP to cache intermediate code at all. Certainly mod_perl, mod_python, and the various CFML engines don't require any special effort to cache intermediate code for each page. That is to say nothing of JIT, although there appears to be some progress being made there with regard to PHP.

    16. Re:Interpreted Languages... by butlerm · · Score: 1

      Are there any languages other than C and assembly language that suffer from string buffer overflow problems? C++ certainly doesn't, not if you use any kind of C++ string library, and one would of course be insane to write non-trivial C++ code without one. That is why no one does.

      One of the things that shocks me is that parsing to bytecode is considered a major performance optimization in the PHP world. Every BASIC interpreter in the world did that thirty years ago, on machines with less than 16K of RAM. Otherwise useful programs wouldn't fit in memory, to say nothing of running at a non-glacial speed. Can't throw cycles away when dealing with a 1 Mhz CPU.

  20. Umm... no. by NitroWolf · · Score: 3, Insightful

    Does the author seriously believe that Facebook isn't running some sort of PHP compiling/caching service, like APC or something similar?

    It would be ridiculous for them NOT to be running something like that, which eliminates much of the advantage C++ would enjoy through being pre-compiled. While there still may be a reduction if Facebook were magically changed to precompiled C++ code, the reduction would be fairly minimal. In addition to that, you'd need to factor in the debugging and coding/compiling times, which would exceed the PHP times by an order of magnitude at least.

    1. Re:Umm... no. by mariushm · · Score: 4, Interesting

      The author is pulling numbers out of his ass and has no clue about what uses most time (waiting for database results mostly), about PHP accelerators and about caching systems like memcached.
      He's comparing performance of php script running on a raw PHP installation versus running a C++ version of the same script, doing calculations that almost never apply to real world scenarios.

      I don't see how any company would use C++ to develop their whole systems except maybe for some CGI scripts. Not even Google does it, afaik they use Perl and Python a lot.

      Anyway, the number of servers has no direct correlation to the programming language. Out of those thousands of systems, lots of them are read only database servers in a cluster, lots are only serving static files (thumbnails, images used in CSS files on people's pages and so on), some servers are used solely for memcached instances and content used very rarely, some are load balancers....

      Basically, the author has no clue.

      I always found Livejournal's presentation about scaling very insightful, especially as it's a pretty big site, just like Facebook and other big time sites. The second link gives a lot of details about how they fine tune mysql and other parts of the system, which just goes to show how the apparent speed improvement of C++ versus PHP can overall be actually insignificant.

      http://video.google.com/videoplay?docid=-8953828243232338732&ei=3VUuS5-hLaKi2ALXqanJBQ&q=livejournal#
      http://www.danga.com/words/2004_mysqlcon/mysql-slides.pdf

    2. Re:Umm... no. by butlerm · · Score: 2, Informative

      the author...has no clue about what uses most time (waiting for database results mostly)

      Like many here, you are confusing page delivery latency with total processor overhead. If you need more than one processor for page processing, how many you need has little or nothing to do with how much latency there is elsewhere in the system.

    3. Re:Umm... no. by Anonymous Coward · · Score: 0

      They use a lot more than that... They've written their own extensions to php to bypass most of the traditional bottlenecks. Since you write the extensions in c or c++ anyway those speed sensitive parts run exactly as quickly as they would if the entire application were written in c or c++.

    4. Re:Umm... no. by Anonymous Coward · · Score: 0

      The author is pulling numbers out of his ass and has no clue about what uses most time (waiting for database results mostly), about PHP accelerators and about caching systems like memcached.

      I was always under the impression that "waiting for database results mostly" is does not actually consume processing power and thus the OS can switch to another request task (and thus another request)? Why would they not keep their CPUs busy interpreting PHP opcodes rather than wasting money?

      He's comparing performance of php script running on a raw PHP installation versus running a C++ version of the same script, doing calculations that almost never apply to real world scenarios.

      I don't see how any company would use C++ to develop their whole systems except maybe for some CGI scripts. Not even Google does it, afaik they use Perl and Python a lot.

      Anyway, the number of servers has no direct correlation to the programming language. Out of those thousands of systems, lots of them are read only database servers in a cluster, lots are only serving static files (thumbnails, images used in CSS files on people's pages and so on), some servers are used solely for memcached instances and content used very rarely, some are load balancers....

      His first reference has a facebook engineer explaining that "the bulk of the servers is running Apache/PHP. Do you think the facebook engineer is lying or is it rather you that is "pulling facts out of your ass" ?

    5. Re:Umm... no. by SUB7IME · · Score: 1

      This is the correct response. Facebook use (and actively develop) APC, an opcode cache. In other words, they cache the compiled binaries created by PHP. So, the environmental impact of running PHP as opposed to something compiled is virtually 0, because nearly all calls are made to pre-compiled PHP opcode.

    6. Re:Umm... no. by Anonymous Coward · · Score: 0

      Google uses Java and Python a lot. Perl isn't one of Google's approved languages and isn't used for much.

    7. Re:Umm... no. by Anonymous Coward · · Score: 0

      Google search engine is written mainly in C.

    8. Re:Umm... no. by Anonymous Coward · · Score: 0

      http://www.danga.com/words/2004_mysqlcon/mysql-slides.pdf [danga.com]

      Ugh that was painful, the only thing more annoying than a power point presentation is a pdf that thinks it's a power point presentation.

  21. Even if PHP is running 10 times slower... by sam0737 · · Score: 1

    I'm assuming the claim about 10 times is true, which I don't really think so...
    But they could have done something - like precompile the PHP, just like JIT of Java, to make it better or on par with compiled C program.
    There are PHP accelerators like Zend Accelerator for that.

    1. Re:Even if PHP is running 10 times slower... by canajin56 · · Score: 1

      Yeah, in fact, since we're just pulling numbers out of our asses, a quick Wiki check says that PHP pre-compilers give a performance boost of up to 10x, therefore neatly canceling out this d-bags assumed 10x ratio. Yay for fictional numbers.

      --
      ASCII stupid question, get a stupid ANSI
    2. Re:Even if PHP is running 10 times slower... by butlerm · · Score: 1

      PHP is a dynamically typed language like Perl or Python. As such, in general it *cannot* be compiled to run as fast as code written in a statically typed language like C++. Look up the state of the art for JIT of dynamic languages some time. Works pretty well on numeric calculations, on everything else not so much.

      Now of course that may not make much of a difference if the environment concerned isn't really limited by the PHP execution speed.

    3. Re:Even if PHP is running 10 times slower... by I+cant+believe+its+n · · Score: 2, Insightful

      IBM is working on a PHP compiler to create bytecode for the JVM. Using P8 as it is called, you can run your compiled PHP programs on a java application server such as Tomcat or JBoss.

      --
      She made the willows dance
  22. Morons. by Luke727 · · Score: 1, Informative

    This is why people don't take global warming seriously. Please, just stop it. If you really wanted to help, you could just fucking kill yourself and cut your carbon footprint to 0.

    --
    If you find this post offensive, don't read it! THINK ABOUT YOUR BREATHING! I am what I am because of how apes behave.
  23. A trolling weak argument by Foredecker · · Score: 4, Insightful

    What a troll. Any point or argument based on assumptions is very weak. Here there are two: "..Let's assume this to be ..." and "...assuming a conservative ratio of 10...".

    Don't make stuff up.

    -Foredecker

    --
    Jibe!
    1. Re:A trolling weak argument by Anonymous Coward · · Score: 2, Funny

      Any point or argument based on assumptions is very weak.

      -Foredecker

      Assuming unreasonable assumptions of course.

    2. Re:A trolling weak argument by abegosum · · Score: 1

      Logic, for the win.

  24. Hidden cost by Anonymous Coward · · Score: 0

    What about the environmental impact of all the coke bottles required to power the C++ programmers?

  25. F1 car in normal street. by Tei · · Score: 1

    This don't make much sense. You can go to work in a F1 car, or your normal car. You in theory will go faster in the F1 car.

    In real world, there are other "fasters". The normal car is "faster to buy" (cheaper), "faster to mantain" (cheaper to mantain), and lots others "faster" that make faster your normal car than your F1 car.
    Facebook is probably one of the few sites that could have written part of it on fast C++ code. In a F1 race, you will use a F1 car.

    --

    -Woof woof woof!

    1. Re:F1 car in normal street. by oddaddresstrap · · Score: 4, Funny

      You can go to work in a F1 car, or your normal car.

      I wish. My F1 always gets stuck in the gutter at the end of the driveway.

    2. Re:F1 car in normal street. by hayriye · · Score: 1

      Facebook is probably one of the few sites that could have written part of it on fast C++ code. In a F1 race, you will use a F1 car.

      Facebook is "24 hours of Le Mans" or "Dakar Rally" than F1.

    3. Re:F1 car in normal street. by neurovish · · Score: 1

      I can't make it to the gutter...the speed bumps get me first.

  26. Things Change, Efficiency Matters by Anonymous Coward · · Score: 1, Insightful

    Many many moons ago efficiency was everything. The CPU was expensive, the developer was (relatively speaking) cheap.

    Then Moore's law really started to kick in, and we needed a paradigm shift. Developers were more expensive, and CPU cycles could be had on the cheap. The mantra was "code it fast, and only worry about efficiency for the bottlenecks if at all".

    Fast forward to almost 2010, and we have web applications deployed on a massive scale. Guess efficiency matters again. Not only from a pure cost standpoint but also from a moral argument to cut back on greenhouse gases. Amazing that more people haven't seen this coming. Especially given that web services are normally free to the consumer, the cost side of the equation clearly matters.

  27. Assuming... by Xugumad · · Score: 4, Insightful

    "assuming a conservative ratio of 10 for the efficiency of C++ versus PHP code"

    ARRRRRGGGGHHHHHHHHHHHHH

    Why? On what evidence? I mean, I hate PHP as much as the next guy, but last time I wrote a web application platform in C++, I got to the end, analysed the result and went "Great, I've made the fast bit even faster. Now, about that database engine..."

    1. Re:Assuming... by butlerm · · Score: 2, Informative

      Latency is a different question than efficiency. If your page generation efficiency is bad, on a small setup the difference may be imperceptible. On a large installation, i.e. one with a large number of servers dedicated to page generation, the efficiency of those servers makes a big difference. Holding latency constant, in a large installation less efficient page generation means more servers. In a small installation, not so much.

    2. Re:Assuming... by Anonymous Coward · · Score: 0

      I wrote my web application in C, used the Linux file system as a simple database, and serve the pages over a home broadband (100 Kbytes/s) internet connection.
      This was by far the fastest solution as it saved me from learning PHP. (you do need to watch the size of user input, but there are plenty of save string manipulation functions to choose from)

    3. Re:Assuming... by chdig · · Score: 1

      Any real php-driven website uses opcode pre-compiling that speeds the execution of a program to such a degree that the stats given on the site you link to are simply way off. Version 5.3 has sped things up even more than their listed 5.2.9, and on a quick check of one of the PHP program examples, there is a blatant misuse of passing by reference, making it look like PHP4 code. Finally, almost none of the examples are based on real-world web development program needs.

      One program on that link that might make sense is the regex, where for 4x the code in C++, you get a program 1/3 as fast (again, compared to unoptimized and old version PHP code).
      C++ code example
      PHP code example

      This is a perfect example of PHP making C++ look like a fools language -- for web development.

    4. Re:Assuming... by dkf · · Score: 1

      Latency is a different question than efficiency. If your page generation efficiency is bad, on a small setup the difference may be imperceptible. On a large installation, i.e. one with a large number of servers dedicated to page generation, the efficiency of those servers makes a big difference. Holding latency constant, in a large installation less efficient page generation means more servers. In a small installation, not so much.

      But you've got to balance it against other costs. For example, Facebook have plenty of PHP programers now but you're suggesting that they all retrain in C++. That's expensive, especially if they've got to keep on delivering new features for their existing platform at the same time until the rewrite is done. (The development cycle for a site like Facebook is furiously short; for eBay, where I've seen the figures, the cycle is a week. I'd be startled if Facebook was much longer these days.) Add in the fact that the cost of adding servers is low and the cost of carbon is low, then you're left in the position of arguing that something very expensive should be done to mitigate some fairly cheap costs. Not gonna happen! (Now, adding a new datacenter is expensive, comparable to building a new highly-automated factory, but it's not clear to what extent switching from PHP to C++ would really mitigate that.)

      --
      "Little does he know, but there is no 'I' in 'Idiot'!"
    5. Re:Assuming... by butlerm · · Score: 1

      Absolutely. But if the case can be made for using C/C++ for a web application front end anywhere, it is with a high volume low revenue per visitor site like Facebook. I am not sure exactly what Google is using for it these days, but I wouldn't dream of using anything other than C/C++ for search page result generation. Talk about pouring money down the drain.

      If I were Amazon, on the other hand, I don't think C++ would be my first choice for the front end. Amazon can afford the overhead of Java/C# or whatever much better than a free site like Facebook can.

  28. c++ is 'write-only' code by TheGratefulNet · · Score: 1

    it sure seems to be, the way a lot of people write it. write it once and hope you never have to read it since its impossible to figure out what they intended. ever read someone's c++ code? has it been a good experience?

    --

    --
    "It is now safe to switch off your computer."
    1. Re:c++ is 'write-only' code by ckaminski · · Score: 1

      Yes, I have. And it ranges the gamut from horrible to beautiful.

      What C++ has always lacked, and PHP, Java and others do not, is a bundle of standard libraries that let you do things like process XML, talk to databases, and make templating EASY.

      That's it. php does the same things C++ does, but go one beyond and add a rich library and of course, the ability to skip the "compile" step in the write -> compile -> test

    2. Re:c++ is 'write-only' code by jimicus · · Score: 5, Insightful

      What C++ has always lacked, and PHP, Java and others do not, is a bundle of standard libraries that let you do things like process XML, talk to databases, and make templating EASY.

      That's it. php does the same things C++ does, but go one beyond and add a rich library and of course, the ability to skip the "compile" step in the write -> compile -> test

      I agree with you, but there's one small thing I don't get.

      Faced with this piece of information, someone thought the logical thing to do was to, er, write an entirely new language?

    3. Re:c++ is 'write-only' code by hedwards · · Score: 3, Funny

      Isn't that how things work in the real world? Your faucet is broken so you burn down the house. Seems like the logical way of dealing with it to me.

    4. Re:c++ is 'write-only' code by mhelander · · Score: 1

      Well, to prepare the ground for the development of rich libraries, a language that doesn't think the umpteen different possible ways to represent a string is terribly exiting stuff and prefers support of them all could be a good start.

    5. Re:c++ is 'write-only' code by kesuki · · Score: 1

      "Faced with this piece of information, someone thought the logical thing to do was to, er, write an entirely new language?"

      by my understanding, the whole new language slant is because of the nightmare of c++ code out there to reuse, with unintended consequences. php is very web centric and java the last attempt at a 'universal' coding setup. python is an example of new language and how more complicated new language implementation is.

    6. Re:c++ is 'write-only' code by betterunixthanunix · · Score: 5, Insightful

      "ever read someone's c++ code? has it been a good experience?"

      Sure, when the code is written by someone who really knows how to use C++. Ever read bad PHP code? Bad Java code? I have seen programmers do things like this:

      int int1, int2, int3, int4, int6, int7;

      No, that is neither a joke nor an exaggeration, and the missing number is deliberate. This is a declaration I saw on a recent project. This kind of poor coding is language agnostic, and it is entirely irrelevant whether someone is using C++, PHP, or even a language like Haskell (bad Haskell code is worse than that worst C++ code I have ever seen -- if you use a functional language, get it right!).

      On the other hand, I have seen some maintainable C++ code, with appropriate and useful comments, well thought out classes and class relationships, and expert use of the STL. I once worked on a project with C++ code that dated back to the early 90s, and had been continuous updated to support new features and needs, to make use of the STL (yes, this can be written into old code without causing a disaster), and so support systems that did not even exist when the code was originally written.

      Don't blame the language, blame programmers who never learned about good programming practices. Blame computer science programs that give people degrees they do not deserve. Blame an industry that will hire anyone who can write a hello world program and then assume that they are capable of writing a maintainable system with millions of lines of code. The best programming language in the world will not solve the problem of poor programmers and poor coding practices.

      --
      Palm trees and 8
    7. Re:c++ is 'write-only' code by Stele · · Score: 3, Insightful

      Maybe you should learn the language first. It seems there are an awful lot of people who love to comment on the complexity and performance of C++, who never bothered to really learn the language. Yet this doesn't stop them from pretending the be experts on it.

    8. Re:c++ is 'write-only' code by betterunixthanunix · · Score: 2, Insightful

      Part of the issue is the culture surrounding C and C++ code: there is a demand for backward compatibility. The C++ standards committee is very wary of breaking compatibility with previous editions of the standard, notwithstanding the breakage that compiler writers introduce. Thus, we are left with antiquated and frankly dangerous features that should not be used, but which novices wind up using anyway.

      Strings are a perfect example. The C++ standard defines a string type that is decent enough and fixes a lot of problems associated with C-style strings. However, because of the demand for backward compatibility, C-style strings remain in the language, remain in use in parts of the library, and continue to wreak havoc on C++ programs.

      I am not saying that the backward compatibility is a back thing -- in fact, I appreciate it very much, given the large body of old but useful code out there -- but I cannot deny that it creates problems. What I am saying is that I can see why someone would develop a new language to replace C++ instead of just writing a C++ library, given that there are a lot of people who write new code using these out of date features, thus creating a stream of horror stories about C++.

      --
      Palm trees and 8
    9. Re:c++ is 'write-only' code by Anonymous Coward · · Score: 0

      What C++ really lacks are comprehensible compiler errors. With gcc the screen is completely filled with a single error message. And all you can really do with that error message is find the line number and look at the code until you see the problem.

    10. Re:c++ is 'write-only' code by Xtravar · · Score: 4, Interesting

      It's more like you decide you want a whole new room dedicated to watching movies, but in order to add that to your current house you'd have to spend tens of thousands of dollars and get approval from city hall and your homeowner's association. Just for a fairly small addition.

      So instead you decide to go build a new house the way you like it, from the ground up, and while you're at it you add ethernet outlets into the planning because you always wanted that in your old house but you would have had to take down the drywall in order to get them where you wanted.

      --
      Buckle your ROFL belt, we're in for some LOLs.
    11. Re:c++ is 'write-only' code by Anonymous Coward · · Score: 0

      > Faced with this piece of information, someone thought the logical thing to do was to, er, write an entirely new language?

      Sometimes creating a new language is the right choice, in order to REDUCE the amount of power and flexibility!

    12. Re:c++ is 'write-only' code by Penguinisto · · Score: 1

      If you can come up with a C/C++ variant that compiles on-the-fly and in near-real-time, there are a lot of people who would happily line up to kiss your ass...

      --
      Quo usque tandem abutere, Nimbus, patientia nostra?
    13. Re:c++ is 'write-only' code by g0at · · Score: 2, Insightful

      What C++ has always lacked, and PHP, Java and others do not, is a bundle of standard libraries that let you do things like process XML, talk to databases, and make templating EASY.

      I agree with you, but there's one small thing I don't get.

      Faced with this piece of information, someone thought the logical thing to do was to, er, write an entirely new language?

      What? Your logic is circular. PHP did not have standard libraries for XML (etc.) until after it existed, obviously.

      PHP was invented as a lightweight server-side preprocessor as an alternative to CGI, not as a general-purpose systems-engineering low-level compiled language.

      (I don't disagree with your gist that PHP is not well suited to many of the jobs it's used for today, but I wanted to clarify the history.)

      -b

    14. Re:c++ is 'write-only' code by debatem1 · · Score: 2, Funny

      "Faced with this piece of information, someone thought the logical thing to do was to, er, write an entirely new language?"

      by my understanding, the whole new language slant is because of the nightmare of c++ code out there to reuse, with unintended consequences. php is very web centric and java the last attempt at a 'universal' coding setup. python is an example of new language and how more complicated new language implementation is.

      Are you suggesting that they wrote PHP to avoid code reuse, that there hasn't been an attempt at a cross-platform language since Java, and that Python is complicated, all in the same paragraph?

    15. Re:c++ is 'write-only' code by thetoadwarrior · · Score: 1

      As someone who has used more PHP than C++, I would still have to say PHP is pretty shit. It's an ugly language. I've seen loads of nice C++, PHP, Java, etc. and loads of awful examples.

      The biggest problem with PHP is that anyone can use it. That is also why a lot of PHP is messy, imo.

      I do hope PHP goes out of style and Python or Scala take its place. PERL is more or less dead but I'd rather see that come back than see PHP stick around.

      It was nice and easy to learn with and yes it's nice to knock out something quickly but once you start using other languages I think PHP really starts to lose its shine.

    16. Re:c++ is 'write-only' code by stonefoz · · Score: 1
      C++ is stuck with C strings, it's wrote into the language.

      char *bad = "this is bad\0 ha ha";
      sizeof (bad); /* returns size of pointer */
      length (bad); /* returns wrong size */

      It shouldn't be a happen unless you don't know where the strings originated, but I don't know of a good way to process that. Meanwhile, for web pages, code generators make code from code from code from code, etc. and inline and cache it all. It just doesn't easily work in C++. I could write a template engine, but it'd just end up as "#include " following by why even bother.

      --
      I think I just cashed out all my cool points.
    17. Re:c++ is 'write-only' code by Anonymous Coward · · Score: 0

      Faced with this piece of information, someone thought the logical thing to do was to, er, write an entirely new language?

      Well, actually I always thought that PHP was a hideous marriage of C and Perl. So hardly a new language. The really "new" part is that web-related stuff has been added. And about 150 mutually-incompatible database interfaces.

    18. Re:c++ is 'write-only' code by Jesus_666 · · Score: 1

      Well, they could have taken C++, added proper string support, changed it from a compiled into a platform-agnostic interpreted language, hidden complicated parts like the heavy reliance on the preprocessor and pointers, added easier array and dictionary management and then added a completely new standard library...

      But by then their web-friendly C++ (Let's call it C++Web) would look nothing like real C++ and would most likely be incompatible in many ways. At best, I'd expect a situation like between C and C++ - C++Web could interpret C++ code but you culdn't call C++Web code from C++ without jumping through hoops. The advantage is negligible.


      C++ and PHP are designed to do different things in different ways. While one could bolt things onto C++ until it becomes easy to use for web development, the result would be suficiently different from vanilla C++ that the fact that there's still C++ somewhere in there becomes entirely meaningless. And at that point you can just declare your language to be independent of C++, which allows you to toss out cruft you don't need.

      --
      USE HOT GRITS WITH STATUE OF NATALIE PORTMAN (NAKED AND PETRIFIED)
    19. Re:c++ is 'write-only' code by Anonymous Coward · · Score: 0

      I know it doesn't need to be said, but all your arguments are NOT a language problem. They all condemn the language for a few bad developers you've apparently seen.

    20. Re:c++ is 'write-only' code by BitZtream · · Score: 1

      Yes, I have, massive amounts of it.

      Guess what, PHP is generally worse.

      PHP is far younger and PHP devs are generally less experienced than the devs who write the C code I deal with.

      If you think language has anything to do with ability to write readable code I suggest you get a few more years and languages under your belt.

      Any language can be ugly, web scripting languages are generally the worst in this respect due to the people who intermix logic and presentation layers into one mess of code.

      --
      Persistent Volume manager for Kubernetes - https://github.com/dwimsey/openshift-pvmanager
    21. Re:c++ is 'write-only' code by Anonymous Coward · · Score: 0

      Centralized

      Not made here.

      Perl was revolutionary in that they had CPAN.

      Perl can update itself. Perl could query CPAN for the module you needed.

      perl -MCPAN -e 'shell'

      PERL lets you write code in stream on the command line. Modular, adaptable.

      C++ remains in the hierarchical realms of power and control.

      An elaborate festival must be put on in order to develop an idea into fruition.
      Create a template, write your idea in the confines of a limited space, break concentration to compile the code therefore switching skill-sets.

    22. Re:c++ is 'write-only' code by BitZtream · · Score: 1

      Uhm, PHP doesn't have its own XML parser. It uses the same one I do as a C programmer. Uses the same database libraries I do. Different templating systems mostly.

      The problem with this stupid statement is that PHP is written in C and so most of what you're calling 'a standard library' C developers have as well. As well as a bunch of others.

      My development tools let me write code while I'm executing it in the debugger so my process is something like, write -> compile -> debug/modify/test -> Use.

      Your process is write -> compile and execute/test -> change code -> compile and execute/test.

      Everytime you run a PHP it guest compiled, or more appropriately interpreted. If you're using a proper caching library then you only compile when you change ... which then, you are just getting back to the traditional model of C dev.

      PHP doesn't have an advantage here, you just don't realize you're compiling every time you view the page.

      If you're using GCC and friends for C/C++ related web dev, then yes, it fucking sucks, get a real compiler and IDE and you'll have a much more pleasant experience.

      --
      Persistent Volume manager for Kubernetes - https://github.com/dwimsey/openshift-pvmanager
    23. Re:c++ is 'write-only' code by Anonymous Coward · · Score: 0

      I know, right? Everything was fine when there was only one programming language, and now there's two and it's like aaaargh I can't decide...

    24. Re:c++ is 'write-only' code by Almahtar · · Score: 1

      php does the same things C++ does, but go one beyond and add a rich library and of course

      So it has multiple inheritance, namespaces (ok it *finally* has those), compiler-guaranteed type safety (some don't like this feature, but you can't say it's the same thing that's for sure), and metaprogramming/templating? I'm pretty sure it has none of those, and its OO implementation is pretty terrible in general. PHP is great for making a quick web page or simple web app, but once you get into more complex projects the simple static traceability of C++, not to mention multiple inheritance and the like, start to pay off in huge ways. The speed, while still an advantage (even just in symbol table lookups), isn't near as much a factor as the development time is.

    25. Re:c++ is 'write-only' code by Surt · · Score: 1

      Java?

      --
      "Who is the Journal of Quantum Physics going to believe?" --Stephen Hawking
    26. Re:c++ is 'write-only' code by Anonymous Coward · · Score: 0

      ZOMG! Pointers are evil!!!

      Read any "C++ for dummies in 21 day" book - it'll help you. Pointers are not the problem - pointers are the feature. Do not know how to use them? - Do not.

      P.S. If we are to speak about C++, then you have to write like that:

      char const *bad = "this is bad\0 ha ha";

    27. Re:c++ is 'write-only' code by Dragonslicer · · Score: 1

      The biggest problem with PHP is that anyone can use it. That is also why a lot of PHP is messy, imo. I do hope PHP goes out of style and Python or Scala take its place. PERL is more or less dead but I'd rather see that come back than see PHP stick around.

      You honestly think that the idiots out there writing horrible PHP code won't write equally horrible code in whatever other language you put in front of them?

    28. Re:c++ is 'write-only' code by Bright+Apollo · · Score: 1

      PHP does the same things as C++? Really? And C++ lacks standard libraries to process XML, connect to DBs..? Interesting assertions. Cite sources, because from what I understand, C++ has tons of libraries and templates, and does things that lots of languages including PHP cannot do... operating systems, real-time applications, and compilers spring to mind.

    29. Re:c++ is 'write-only' code by maxwell+demon · · Score: 1

      He said C/C++ variant. Apart from superficial syntactic similarity, Java is a very different language from C++.

      --
      The Tao of math: The numbers you can count are not the real numbers.
    30. Re:c++ is 'write-only' code by maxwell+demon · · Score: 1

      And if you want to write good C++, you'll write

      std::string bad("this is bad\0 ha ha", 18);

      Note that the C wart is still visible, in that if you wouldn't give the length explicitly, the string would only contain "this is bad". In C++0x this could be solved by a user-defined string literal, which would allow you to write something like

      std::string good = "this is good\0 if provided"s;

      It would be nice if the standard provided this literal definition, but looking at N3000, I couldn't find it (but then, the whole thing is huge, so I might very well not have seen it). However, it's possible to write that definition yourself.

      --
      The Tao of math: The numbers you can count are not the real numbers.
    31. Re:c++ is 'write-only' code by Anonymous Coward · · Score: 0

      due to the people who intermix logic and presentation layers into one mess of code.

      If your presentation code doesn't involve logic, I'd hate to see how it does work....

    32. Re:c++ is 'write-only' code by Anonymous Coward · · Score: 0

      Also, you run the new house by interpreting the old house... so really you're just saying it's a new house but it's actually built around the old house and you tricked city hall and your homeowner's association.

    33. Re:c++ is 'write-only' code by neoform · · Score: 1

      Dude, clearly int3 is the third int of a group of 7 ints.. what's not to get?

      --
      MABASPLOOM!
    34. Re:c++ is 'write-only' code by Feyr · · Score: 1

      in fact, i'd go as far as saying as the best programming language in the world pretty much ensure it will be unmaintanable. since most people that write exclusively in them don't understand the underlying abstractions

    35. Re:c++ is 'write-only' code by shaitand · · Score: 1

      What is a language other than syntax? On the fly C would still be C because of the syntax. The execution, compilation, and internals don't matter. The language is the syntax.

      Java would still be java if you wrote a native code compiler.

    36. Re:c++ is 'write-only' code by shaitand · · Score: 1

      "What? Your logic is circular. PHP did not have standard libraries for XML (etc.) until after it existed, obviously.

      PHP was invented as a lightweight server-side preprocessor as an alternative to CGI, not as a general-purpose systems-engineering low-level compiled language."

      Which of his examples has anything to do with non-web related tasks? XML certainly wasn't such an example.

      Maybe I started looking at PHP late but I don't remember PHP ever not having its web related built-ins?

    37. Re:c++ is 'write-only' code by Anonymous Coward · · Score: 0

      Except its more like building your house 10x larger for no particular reason so it takes 10x longer to go from the lounge to the bathroom and you need a long stick with a funny hook thingy to open the window.

    38. Re:c++ is 'write-only' code by Waccoon · · Score: 2, Insightful

      Ever read bad PHP code?

      My hobby is refactoring PHP code. Note I say hobby, and not job.

      After cutting my teeth with C, I moved on to web development with Perl. I was really annoyed at all the quirks in that language, namely, bizarre subroutines instead of functions, and clever regular expressions everywhere. Perl was just a pain, and I still don't like it! So, I decided to give PHP a spin, and I liked it because it was closer to the C code I used to write.

      It didn't take long for me to realize there was something seriously wrong with the language. After reading up on its history, I realized the problem: PHP is a crappy template engine that has been "upgraded" into a language over the course of many painful years. Horrible inconsistencies and limitations abound, names of functions make little sense, and it's taken years for even the most basic facilities to be kludged in. References work in reverse? I have to test for automatic quotes at runtime to make sure I don't double-encode input? Some text functions are binary safe and others aren't? Completely different APIs for MySQL 4 and MySQL 5? Yeah, okay... thanks.

      I went out of my way to study the language and write code correctly, but I can't blame people for writing bad PHP code. PHP is the Windows of the web development world. Nobody really designed it, it just kind of "grew" out of some little hack project and caught on among the rookies.

      The only reason I work with PHP is because I want to make redistributable code that will work on shared servers, where people cannot install a new language on the server. Perl and PHP are your only options for that, and Perl can be a bitch to get running correctly, depending on the server's security policy. I don't care if Python makes a comeback or Ruby catches on, or whatever. I just want... something else to work with.

    39. Re:c++ is 'write-only' code by Anonymous Coward · · Score: 0

      int int1, int2, int3, int4, int6, int7;
       

      Please tell me why. I mean, there is a why, right?

    40. Re:c++ is 'write-only' code by chthon · · Score: 1

      Python is older than Java...

    41. Re:c++ is 'write-only' code by ivucica · · Score: 1

      I have no problem with apt-get install libxml2-dev etc. I have problem with painting images in a sensible way without GD. With C++ that's just too much work, especially if you don't use SDL and SDL_image for whatever reason. Even then SDL_image can't encode images.

      When it comes to skipping compiling, that's actually a bad thing in my experience. Compile-time type-checking is something that greatly helps you avoid many mistakes, and also I'd love to be able to occasionally distribute compiled PHP code. Best I could do seems to be PHC's obfuscation; not even compiling, since you can't give that to other people to install on shared hosts and such.

    42. Re:c++ is 'write-only' code by CodeBuster · · Score: 1

      The best programming language in the world will not solve the problem of poor programmers and poor coding practices.

      In my experience, the problem is more often due to inept hit and run management getting into a project, causing chaos among the dev teams, and then bailing for a new job or a promotion before the full harmful effects of their meddling become apparent. For example, they may "trim the fat" from the schedule without realizing that they have completely ruined the system by forcing premature release with abbreviated testing (i.e. the customers can do the testing so we don't have to worry about that now) or perhaps they insist upon a certain sub-optimal technology being used without understanding the implications or just to be "buzzword compliant". These poor decisions often have a ripple effect throughout the entire project, completely overshadowing any redeeming features that might have otherwise averted a complete disaster. These managers believe that their oh-so-smart MBA degree certifies them to contribute to anything, including software development, with superior results when in fact it only certifies their stupidity.

    43. Re:c++ is 'write-only' code by maxwell+demon · · Score: 1

      What is a language other than syntax?

      Semantics. Java objects are very different from C++ objects (to start with, they don't support value semantics), Java generics are radically different from C++ templates, and the semantics of Java volatile is completely orthogonal to the semantics of C or C++ volatile (although it's a common error in C or C++ to use volatile as if it had Java semantics).

      --
      The Tao of math: The numbers you can count are not the real numbers.
    44. Re:c++ is 'write-only' code by Anonymous Coward · · Score: 0

      Network cable slinger here. Any network installer worth his paycheck can add a drop for you with just a hole in the wall that'll be covered by a faceplate and an even smaller hole above the ceiling/below the floor that should be patched/sealed anyway. Fishtape and the like exist solely so we don't have to tear down walls for addons.

      Just sayin'.

    45. Re:c++ is 'write-only' code by kesuki · · Score: 1

      not intentionally but at least you got modded funny pointing out how naieve i am about coding.

  29. Write it in Java! by Anonymous Coward · · Score: 0

    facebook should be re-written in Java.

    It could run on a java interpreter, written in java, that would give it ultimate speed compared to C++.

    C++ is dying, netcraft confirms it, Java is faster than C++, it's the wave of the future!

    1. Re:Write it in Java! by Anonymous Coward · · Score: 0

      Fools, they should have written it in ASP.NET. Just ask Microsoft.

  30. What a fucked up "assumed" "conservative" ratio by nedlohs · · Score: 1

    Yeah right serving a page out of cache in PHP takes ten times as long as C++.

  31. How about this comparison by YrWrstNtmr · · Score: 1

    Plain text vs. any web graphics. Who needs all that fancy graphics crap? If you can't get your message across with plain ASCII, then you are incompetent, lazy, and on the verge of being a mindless PowerPoint Ranger.

    1. Re:How about this comparison by wik · · Score: 2, Funny

      Alright wise guy. Explain twitter.

      --
      / \
      \ / ASCII ribbon campaign for peace
      x
      / \
    2. Re:How about this comparison by geminidomino · · Score: 1

      What about it? Are you confusing a conditional with a biconditional?

  32. Hells about to freeze over ... by LizardKing · · Score: 4, Interesting

    .. because I didn't ever think I'd be defending PHP.

    However, it is a much better choice for a web application than C or C++ - and I say that as someone who codes C, C++ and Java for a living. There are no decent web frameworks for C++, memory management is still an issue despite the STL, and the complexity of the language means both staff costs and development time are inflated. Peer review is harder, as the language is fundamentally more difficult to master than PHP. Compared to Java, the development tools are poorer, and things like unit testing a more complicated despite the availability of things like Cppunit. There's no "standard" libraries for things like database access, and no literature that I am aware of that describes how you would go about designing a framework for C++. You'd most likely end up porting something like Spring to C++, and the even if you published your code on the web, I doubt much of a community would build up around it.

    If you want a less contentious argument, and one which can be backed up with hard evidence, then argue PHP that should be replaced with Java. A well written Java web application, using a lightweight framework such as Spring or PicoContainer, should outperform ad-hoc C++ code.

    1. Re:Hells about to freeze over ... by mebrahim · · Score: 2, Interesting

      Your C++ info is so 90s. FYI:
      A descent C++ web framework: Wt
      Memory management is a non-issue with RAII, smart pointers, Boehm garbage collector, and finally Valgrind.
      Qt or LiteSQL don't need to be "standard" to do their job.

    2. Re:Hells about to freeze over ... by dkf · · Score: 1

      Memory management is a non-issue with RAII, smart pointers, Boehm garbage collector, and finally Valgrind.

      This smells like an argument you've wheeled out before.

      Firstly, Valgrind is not something you use on a production deployment of a webserver; it's performance overhead is really substantial. (Good tool, but makes all memory accesses much slower.) Your suggestion makes me suspect that you don't write high-performance websites for a living. (There are nasty gotchas if you don't go fast enough.)

      Secondly, RAII only solves some kinds of memory problem (where other languages would use a finally clause) and it is not syntactically clear when it's being used (not unless you're only using it close to the declaration of the class concerned, but that's got other issues). It's OK when you can bind the object lifetime to a scope, but that's definitely not always true. Smart pointers are better general tools, but rather noisy and inefficient (their refcount management is necessarily conservative and so ends up adding some overhead, which is not necessarily good for cache coherency). They also don't tackle circular structures (if that matters to you).

      Lastly, full GC has substantial costs of its own (it increases memory consumption of the application, and churns that memory around more rapidly) and a generational collector will outperform pure Boehm on many workloads, though the fact that the Boehm collector supports thread-local allocation is a big plus; a lot of workloads can be split nicely into parts that are constrained to a single thread. The Boehm GC is good, but is it the right kind of good for a website implementation? I'd need to see some evidence - not just opinion - before commenting in depth.

      --
      "Little does he know, but there is no 'I' in 'Idiot'!"
    3. Re:Hells about to freeze over ... by mebrahim · · Score: 1

      Of course Valgrind is not for deploying! It is used to find memory bugs while developing.
      Thanks for the laugh! :D

    4. Re:Hells about to freeze over ... by uninformedLuddite · · Score: 1

      Your C++ info is so 90s.

      Just like your birthdate

      --
      The new right fascists are bilingual. They speak English and Bullshit.
    5. Re:Hells about to freeze over ... by Anonymous Coward · · Score: 0

      Just like your birthdate

      Ageism... you should be ashamed. :-(

    6. Re:Hells about to freeze over ... by Anonymous Coward · · Score: 0

      Java sucks for web development. I work in jsp/java/oracle every day and it absolutely blows. It completely over complicates things. You use toplink to read from the database, then map to the domain model, then map to the form, then use the form in jsp render. You've got all these xml files flying around and don't even get me started on the "expression language". Java shouldn't be used for web programming because the objects don't stay around! It makes no sense, all you ever need to do for web development is to write strings. The language was made to hold objects that stay around for an extended period of time (hence the need for "garbage collection"), but in web programming, all you really end up creating are structs that represent rows in the database and "classes" that are basically just groups of functions. Once you've pull the stuff from the database and written the response, all those objects are gone. They served no purpose but to slow everything down.

      I'm all for three-tiered design, but as I've witnessed at my current job, you can even screw that up in java. PHP, python, perl are good because the http protocol is stateless. It doesn't fit well with event driven programming where the program sits there in a state, the user does something, and then depending on what that was, the program alters its state. That's what java (and c++ and c#) are good for. Real applications (like web servers) that stay in memory for more than a few seconds. For a web "application", the "state" of the program is the database. So, all you really need to do is to modify that. That's why scripts are better. They get a request, change the database based on what was sent and then show the results. That's all they ever need to do, that's what they're made for. They don't hang around waiting for more user input, that's what the web server does.

      And some people might talk about "maintainability". You can screw up in java as easily as you can screw up in php. As a matter of fact, because java adds so much unneeded complexity to code whose ultimate purpose is to create and show the results of an sql query, I'd argue that java code is less maintainable than php, perl, or python because there's bound to be so much more of it.

  33. optimization by TheSHAD0W · · Score: 1

    It's likely most of the overhead in Facebook's server farm is database-related and not PHP-related, meaning switching to C++ would not help much. Also, depending on what tasks the PHP codeebase is performing, one can write binary libraries to speed up critical portions of the operation, improving performance to near-total-binary without reducing maintainability. I wouldn't be surprised if the people at Face book were already aware of this.

    1. Re:optimization by pmontra · · Score: 1

      It seems that they already optimized into C++ what was worth optimizing. From the linked Facebook's presentation:

      Back-end services that require the performance are implemente [sic] in C++.

      Comparing carbon footprints is pretty complex: everything produces carbon, even optimizations, architectural changes, extra developers needed to create and maintain more complex systems written in less web-friendly languages, and I'm no fan of $this-> PHP thing ;-) Maybe this guy at webtoolkit should have made some more assumptions before writing that post.

  34. what about production/maintenance costs by unity100 · · Score: 1

    developing web applications in c is not exactly a walk in the park. neither c was designed to build web applications, or maintain them. whereas you can easily go through php code to develop new functions and improve new and existing functions efficiency speedily and economically, it wont be the sam with c. what about those costs ?

    looking at the instantaneous state of the server/php/performance situation is as stupid as just looking at the instantaneous state of a mass production factory and declaring that certain assembly lines are not efficient or green. there are a lot many factors and costs to count into in the bigger picture.

    a half assed approach, which, somehow, brings the word 'green' into the mix - maybe to garner some attention, since it is the issue these days.

    1. Re:what about production/maintenance costs by Anonymous Coward · · Score: 0

      developing web applications in c is not exactly a walk in the park.

      The article is about C++, not C (and if you think they're the same thing, you don't have the right to an opinion on the subject).

  35. eh by unity100 · · Score: 1

    as with ALL things invented by humans and which can be used to create other stuff, php has grown over the 'homepage tools' it was initially created to be. now not only it has a huge set of functions inside it to create full fledged applications, but through server modules it can also acquire an immense sea of functionality that can be used to perform innumerable other tasks. it is pretty much at the point where it can take over some desktop applications too, with the right server setup and modules - with some scripts and the proper modules you can even do a fair amount word processing in any web front app. to the extent of being able to do drag&drop editing/drawing and pdf creation and so on. of course not quite as efficient as a native desktop program, however, regardless, you can.

    just check php functions in php.net, and check some modules apache can use to supplement php. there is QUITE a lot.

  36. He's not wrong.... But... by pjr.cc · · Score: 3, Interesting

    Seriously, years ago I started working on a c++ version of j2ee (not just servlets, the whole kit) and i mean providing similar functions not identical methods of execution obviously. It wasnt terribly hard actually. But it all falls apart really quickly cause of several reasons:

    1) platform architecture - the dependence here, even between different versions of the same distribution was a pain and essentially spelt the end of my work. So I was stuck with "do i make web apps c++ soruce, or shared library binaries?" to which there is only one real answer for portability - source.
    2) its a systems langauge - dear god that makes it painful for so many reasons.

    There are caveats to both those, but the reality is that php exists because it fulfils a need and it does it quite well. To compare the two (c++ and php) is a little ridiculous and ultimately this article just reeks of "please everyone advertise my c++ web tool kit for me!". Sure, facebook (and trillions of others) MIGHT move to c++ web tool kit, but find me a dev that knows how to code an app it, now find me 2, now find me 200 cause thats how many i'd need to write and maintain faceboot apps in c++.

    Even taking the OP's assumtion c++ is 10 times more efficient at what php does and that you could actually code facebook in it as actually acurate and that php vs c++ is a one-to-one relationship for things like code maintenance, your still stuck with "how many API's am i going to have to re-write and how many php api's do i use that dont even exist in c++". Its ludicrous to assume that you could drop-in replace php with witty without ending up coding tonnes of c++ code just to do things that PHP already provided. Not to mention the zillions of little extensions that revolve around php to accelerate its web-abilities (memcached for example). The number of things that can be used along side php for web-related things and the number of api's in-built to php just mean witty is never even going to be viable as an alternative. Lets also not forget there are millions of people round the globe using php for web stuff - which ultimately leads to php being a good web language (i.e. security problems being found, optimizations, etc etc).

    Of course, wouldn't facebook be using something like zend to compile php pages? I mean seriously, if the 25000 servers are running php and not running zend the waste here just in cost of servers would be unbelievable - shear idiocy on facebooks part (if it were true, and i'd very much doubt it) and I imagine zend would have almost given it away for free just so facebook could say "we got a x% improvement using the zend compiler".

    So, I wonder how many people are now learning about witty for the first time (which seems like the only real reason for the article to begin with). Better advertising than adwords!

    1. Re:He's not wrong.... But... by istartedi · · Score: 1

      The number of things that can be used along side php for web-related things and the number of api's in-built to php just mean witty is never even going to be viable as an alternative. Lets also not forget there are millions of people round the globe using php for web stuff - which ultimately leads to php being a good web language (i.e. security problems being found, optimizations, etc etc).

      In other words, PHP is "good enough" and more popular. It's the winnner.

      We see this a lot in computing. In order for people to consider switching, the technology has to be more than incrementally better. Switching costs are HIGH.

      When switching does occur, it occurs slowly. People didn't just snap their fingers and ditch their expensive Sun boxes for commodity Intel hardware. That switch is taking years. Even when the Sun box cost 10x as much as the Intel+Linux setup, if you had already paid for the Sun hardware, you were not going to switch.

      --
      For all intensive purposes, "whom" is no longer a word. That begs the question, "who cares"?
    2. Re:He's not wrong.... But... by Anonymous Coward · · Score: 0

      "Seriously, years ago I started working on a c++ version of j2ee "

      There's always opensrf, that does something, and as far as I know, more than j2ee it that works with both c, perl and python (java is not yet implemented). See

      http://open-ils.org/dokuwiki/doku.php?id=osrf-devel:benefits_of_opensrf_over_other_application_frameworks

      also, afaik, it's quite stable.

    3. Re:He's not wrong.... But... by ZerdZerd · · Score: 1

      Facebook uses Alternative PHP Cache and has contributed a lot to the project.

      --
      I'm not insane! My mother had me tested.
  37. Re:it's stoopid because by sqlrob · · Score: 2, Insightful

    And everything exuding heat is perfectly natural, no problems there.

    The deaths and environmental changes from heat exchange in rivers near power plants don't happen, nope, uh uh.

    Water's perfectly natural you need it to live, no way to drown in it, nope, uh uh.

  38. PHP vs C++?? by Hurricane78 · · Score: 1

    That’s like a cage match between a slow drooling retard and your crippled grandpa in his electric wheelchair.

    In other words: Run it at double speed, add Yakety Sax to it, and it’s awesome. :D

    --
    Any sufficiently advanced intelligence is indistinguishable from stupidity.
  39. Take it further by Anonymous Coward · · Score: 1, Funny

    Code it in Asm, and you can get 100:1, so you can power down 29,700 machines...

    Better yet, make ppl. post all their wall posts directly in binary code. That way, you can destroy the code necessary to translate UTF-8 back-and-forth, the HTTP/MIME wrappers, and the SQL. Imagine the amount of electricity saved! You can market it as a brain-booster too, since now you have to think before you post on Facebook.

  40. Author needs a clue about metrics by bokmann · · Score: 4, Informative

    Yes, PHP is a heck of a lot slower on proccessor-bound tasks than C++. In a pure benchmarking contest, no doubt C++ will win.

    But what about when both languages have to query a database (be it mysql/postgress/oracle, etc)? In this case, both are blocked on the speed of the database. a 15 ms query takes 15 ms no matter what language is asking. Facebook is not calculating pi to 10 gazillion digits, and it is not checking factors for the Great Internet Mersenne Prime Search. It is serving up pages containing tons of customized data. This is not proessor-bound... it is I/O bound both on the ins and outs of the database and the ins and outs of the http request. It is also processor bound on the page render, but the goal of this many machines is to cache to the point where page renders are eliminated.

    Once a page is rendered, it can be cached until the data inside of it changes. For something like facebook, I bet a page is rendered once for every ~10 times it is viewed by someone. Caching is done in ram, and large ram caches take a lot of machines.

    So lets look at those 30,000 machines not by their language, but by their role. We can argue the percentages to death, but lets assume 1/3rd are database, 1/3rd are cache, and 1/3rd are actually running a web server, assembling pages, or otherwise dealing with the end users directly (BTW, I think 1/3rd is way high for that.)

    So 1/3rd of the machines are dealing with page composition and serving pages. If they serve a page ~10 times for every render request, then abtou 1/10th of the page requests actually cause a render... the rest are being served from cache. Those page renders are I/O bound, as in the example above - waiting on the database (and other caches, like memcached), so even if they are taking a lot of wait cycles, they are not using processor power on the box. The actual page composition (which might be 20% of the processing that box is doing), would be a lot faster in C++... So 10,000 servers, the virtual equivalent of 2000 are generating pages using php, and could be replaced by 200 boxes using stuff generated in C++.

    So the choice of using php is adding ~1800 machines to the architecture. or ~6% of the total 30,000. Given that a php developer is probably 10x more productive than a developer in C++, is the time to market with new features worth that to them? I bet it is.

    1. Re:Author needs a clue about metrics by butlerm · · Score: 1

      For something like facebook, I bet a page is rendered once for every ~10 times it is viewed by someone

      That is less true for an application like Facebook than just about any application imaginable. All the common pages are live or nearly live feeds customized on a user specific basis. Unless I view the same page (without updates) ten times within ten minutes what you suggest is extremely unlikely to be true.

      It is serving up pages containing tons of customized data. This is not proessor-bound

      You are confusing total overhead and total latency. Latency is not the issue here, but rather how many processors you need to handle the load. If a language runs ten times as slow, it will take ten times as many processors to service a capacity limited installation, even if the difference in end user latency is imperceptible.

      All large installations are CPU bound, otherwise they wouldn't add more CPUs, let alone tens of thousands of them.

    2. Re:Author needs a clue about metrics by luzr · · Score: 1
      All of that is expecting that C++ would just replace PHP scripts.

      Anyway, if you want to be really fast, you could completely rewrite the whole thing and add huge data caches managed by C++, removing most of DB traffic in the process.

    3. Re:Author needs a clue about metrics by calzones · · Score: 2, Insightful

      You cache pages on your server so that instead of going to the database to fetch info, the info is already there.

      Until you have a good reason to believe the info has changed. Say, the user updated something or someone posted a message. Then you go back and get new data and cache it again.

      You also cache page components. Parts of the page that are on a different update schedule than other parts of the page may be cached separately or not at all (like ads).

      --
      Asking people to think is like asking them to buy you a new car
    4. Re:Author needs a clue about metrics by butlerm · · Score: 1

      Cacheing pages or page components is great if the cache hit rate is sufficiently high. For many applications (and Facebook is among them), the cache hit rate is far too low to make cacheing *pages* worthwhile. Of course Facebook caches a large amount of non-page data (apart from the caching done in the database), and couldn't operate without it. All that cached data is assembled dynamically for virtually every page request, however. The original article referred to is rather informative on the subject.

    5. Re:Author needs a clue about metrics by ducomputergeek · · Score: 1

      We're moving our infrastructure over to Perl from PHP. When we did testing we found that pages on our sites tended to load in about the same amount of time as it was the Database query and then front-end CSS/JS that took the bulk of the time to load a page, not the script execution time. (We're moving to Perl because there is no PHP connector other than ODBC for the database we'll be moving to and Perl has 2 DBI modules). Plus every time we wanted to do something/add a feature/add an external API, we found there was already a Perl Module for that...

      In my experience in the past 10 years, it's usually been the database that has often been the bottle neck. Seems like any time the traffic was too much with Perl or PHP, adding more hardware with a load balancer always worked until you started to overloaded the database. (Which usually happened first anyway). AND THAT is where you started spending the $$$$.

      --
      "The problem with socialism is eventually you run out of other people's money" - Thatcher.
    6. Re:Author needs a clue about metrics by calzones · · Score: 1

      I don't know what you mean by "far too low."

      If my page is so unpopular that it only gets one hit per day, I'm not likely to be updating it much either. No harm done if it gets cached and no one requests it for another 5 days.

      But if I'm mr popularity, then I may be getting hundreds or thousands of hits per day on my page. I'm obviously not updating it thousands of times per day, so even a 10 second cache will reduce database trips for my page. That's a good thing, esp when multiplied by the total number of popular users.

      Factor in the fact that you can cache components separately, especially anything that is unchanged from page to page within a group on the site, or in some cases unchanged across the whole entire site, and you realize still more savings.

      I don't use Facebook, but what I've observed from a friend of mine who does use it is that he is part of a circle of about 10 people, each of whom is a part of another circle, and so on. Within that 10-person circle, the hit rate will be around once every five minutes per page during peak times.

      What happens then is that the majority of the page remains unchanged every time the page is loaded, but the comment stream changes every few minutes.

      You could cache the comment stream on any given page for 15 seconds and no one would notice because as soon as you post a comment on your own page, the cache for your page would be recreated. 5 seconds later your refresh your page and nothing has changed. But 10 seconds later, you refresh your page and any of your friends new comments show up. The server has just saved itself from at least one database trip. Multiply that by the 5 friends all doing the same thing, and then multiply that by all the other 'circles of friends' on FB concurrently and it starts to really add up.

      --
      Asking people to think is like asking them to buy you a new car
    7. Re:Author needs a clue about metrics by imakemusic · · Score: 1

      Is this why the latest post I see was apparently 10 hours ago (even after refreshing) when I know for a fact people have been made comments since then?

      --
      Brain surgery - it's not rocket science!
  41. Re:it's stoopid because by Galactic+Dominator · · Score: 0, Troll

    You excrete shit as well. I suppose that sewage pond known as your mom's basement isn't polluted either.

    --
    brandelf -t FreeBSD /brain
  42. Re:it's stoopid because by Cougar+Town · · Score: 2, Informative

    And water isn't a poison, but you'll still die if you drink too much of it.

  43. Stop proselytizing for your cult by digitalcowboy · · Score: 0, Flamebait

    AGW/CC is about as real as Scientology. Shut the fuck up already. "The Environment" has taken care of itself for billions of years. I'm not hurting it and it doesn't need you to save it.

    Beyond that, this post has taken it to a brand new, stupidly religious place. You're now calculating numbers you pulled out of your ass to indict programming languages that you find to be "un-green."

    That's my limit. Go sit in the stupid corner until you learn to interact with intelligent adults again.

    1. Re:Stop proselytizing for your cult by Anonymous Coward · · Score: 0

      This has to do with the dysfunctional political culture in the UK -- New Labour's push to regulate everything. In the new world, someone works hard and starts a company. In the UK, someone whines and tries to create a non-profit so they can be a "campaigner" -- to get a cushy job with an expense account and one of those limos in Copenhagen.

  44. Incompetent developers require more servers by Colin+Smith · · Score: 3, Interesting

    It's a phenomenon we have also noted.

    Sure C++ would be faster running but not necessarily more efficient in terms of dollars.

    I think you'll find that the servers come out of the operational budget, not the development one. So the costs of running 10x more servers don't factor into development effort. The costs should of course be charged back to the dev teams.
     

    --
    Deleted
    1. Re:Incompetent developers require more servers by Gorobei · · Score: 1

      I saw a project that this once: consultants figured that converting a 7M LOC application written in a scripting language (time to deploy a bug fix to prod = 1 hour,) would be a good thing. Three years, $300M later, they deployed a buggy version of the same app (time to deploy a bug fix = 1 month.) But, hey, it's Java and modern and enterprisy.

      Nice way to save $5M in hardware costs guys. Oh, bummer about being basically out of business now, but thanks for all the fish.

    2. Re:Incompetent developers require more servers by Anonymous Coward · · Score: 0

      No, the costs of running 10x more servers should be included in the dev teams' brief. The dev team is paid to write code, not provide power to servers. They are, however, paid to write code that will run within given requirements.

    3. Re:Incompetent developers require more servers by crispytwo · · Score: 1

      Running a server is cheap.
      Paying a developer is not.

      The man hours to create good C++ vs good PHP is vastly different (all else being equal).

      I think it is a couple of things going on here:
      1) finding a good C++ coder to write web code is hard
      2) why doesn't these big server farms start looking at migrating code from PHP to C or C++ when the PHP+web design is solid?
      3) and the simple premise that "as computer power grows, so does the language to interact with it".

      It is clearly faster to write code using PHP than C++. In a couple of minutes, using PHP, I can have a working website. In a hour, I can do the same with Java, and with C++, it would take a 4 hours...

      I'll break down the costs for you:
      PHP - $20
      Java - $100
      C++ - $400

      running a server for a day - $1
      running 10 servers for a day - $10

      so - in the end PHP might be $30, Java $110, and C++ $401

      disclaimer: I write/wrote commercial products in C/C++, java, PHP, C#, and others. Speed to delivery is nearly always primary importance.

    4. Re:Incompetent developers require more servers by Anonymous Coward · · Score: 0

      We are talking about in-house dev teams, are we? Their budget is not determined by the value of their products. The budget just is the costs of the resources they need to get it done (mostly development time). If the solution doesn't fit your requirements you have to put more resources to the dev team.

      If your operational costs are too high you have to options. Shut down servers or raise the dev team budget to fix that problem. I don't really see how writing numbers down on different pieces of paper will help.

    5. Re:Incompetent developers require more servers by guruevi · · Score: 1

      Usually the company doesn't really care how much it costs to keep their shop open as long as it doesn't exceed the cost for income. Since Facebook is a web-company it makes sense that they use a web language. After all, Slashdot runs on Perl too, Microsoft runs on ASP.NET. Now if Facebook was making desktop apps, I would expect them to use a language that optimized the code they wrote into bytecode.

      PHP is fairly good and simple enough for running and programming most linear solutions and can be accelerated quite a bit using the right tools (Zend, eAccelerator, bcompiler). I don't think any management would be happy if their website was down due after running happily for months due to a missed asterisk in int* or because a string couldn't be cast into a float or that their system was hacked due to a missed buffer overflow.

      --
      Custom electronics and digital signage for your business: www.evcircuits.com
    6. Re:Incompetent developers require more servers by Pharmboy · · Score: 1

      Not to nitpick, but you can't really compare /. here. The code base is very limited, and it has been previously discussed that running the code in C instead of Mod_perl wouldn't actually make it faster. Slashdot has already done the math and found that the "savings" were non-existent for their particular application because of the code itself.

      On the flip side, can you imagine trying to debug all the little crap that runs on facebook if it were all written in C/C++? What is the biggest waste is some of the flash games. Just for fun, I have entered "Cafe World" on over a dozen computers, ranging from P4/3gz/1gb up to Core2-9550/4x 2.83gz/8gb, and it takes up from 380mb to 550mb of ram on all of them. *For a flash game*. Yea, those guys at Zynga are really good programmers...

      --
      Tequila: It's not just for breakfast anymore!
    7. Re:Incompetent developers require more servers by jsailor · · Score: 1

      Using real world data from real environments...

      the cost of running a server is $3,000-$6,000 / year. The wide variation is due to differing data center resiliency profiles and utility costs (power, water).
      That figure includes data center costs (space, power, cooling, utility, etc.) and excludes server operations staff, depreciation of hardware, support systems, backup systems, network, etc.

      Firms that understand this and bill back the business units appropriately have markedly different environments.

    8. Re:Incompetent developers require more servers by Unoti · · Score: 1

      Just for fun, I have entered "Cafe World" on over a dozen computers... and it takes up from 380mb to 550mb of ram on all of them. *For a flash game*. Yea, those guys at Zynga are really good programmers...

      Not to nitpick, but maybe they really are really good programmers. In game programming, it's quite difficult to both come up with an idea that people will want to play, and then actually execute it. Maybe they're not all that bad after all. Further, it's really OK for an application that is taking front and center of a user's attention to go ahead and take 25% of the available memory on the machine, regardless of its development platform. Live a little! If the app had to be written in C++, it wouldn't exist.

    9. Re:Incompetent developers require more servers by Pharmboy · · Score: 1

      granted, but it is really, really bloated. if you ever played it, you would likely conclude that while the game is pretty cool (I am a fan, really) it is bloated to the point of it interfering with the fun. It makes insane amounts of sql calls for every little thing as well, so when their servers are busy, the smallest event in the game lags. It has been out long enough that they should have worked out some of the bugs, and maybe 100mb worth of bloat.

      --
      Tequila: It's not just for breakfast anymore!
  45. gay as in south park gay by Anonymous Coward · · Score: 0

    gay, don't care

  46. A C app would be much faster by Anonymous Coward · · Score: 2, Informative

    The proposed ratio of 1:10 is real, if not bigger. And here's why:

    1.) For each request, PHP has to load entire application responsible for that particular response, including its configuration, etc. With memcache(d), you have to instantiate connection classes and reconfigure them, per request. Languages like C/C++, Python and Ruby have different architecture to begin with. They load ONCE and each request triggers a FUNCTION or METHOD of a class, with all the app-specific configuration, db and memcached connections done and configured on app init, NOT per request.

    2.) TFA mentions microsecond relevance! Even a simple echo "Hello World" will take much more time than similar action in C. I have yet to see a PHP helloworld app that does it in under 1msec, let alone the microseconds required.

    3.) Arrays in PHP are slow, being always hashmaps. Other data structures can speed up things. You don't always need hashmaps. SPLFixedArray() is a joke, btw, and available only as of 5.3. Can't compare it to a vector anyways, and lots of fixed structures can be represented by structs or classes in C which are anways faster than in PHP. Also the app can instantiate them once on init, and just (re)load when required.

    4.) Even if all the app does it parse input vars and call memcache(d) / database funcs/methods to retrieve/store data, those calls are faster in C. Params can be parsed quicker in C, not requiring hashmaps for instance.

    5.) FastCGI is crap. If this app were to be done in C, then it would require its own HTTP layer, epoll based (for Linux). It can take out all the crap in HTTP that is not requred to parse the AJAX calls, and does not need to be "generic" enough to deliver static content.

    6.) For such dedicated and distributed deployments, garbage collection is sometimes not required. For instace, fixed-length stuctures can be preallocated upon app init, and the app can really take as much RAM as possible on startup. Yes, that would limit the MAX number of users/connections per server, but so what? The app dominates the server, nothing else is required to run (except basic OS environment for the app), so fixed memory consumption is not a problem.

    7.) Even though each request has to wait for I/O of some sorts, either from memcache(d), from disk or from DB, you can process much more of these per front-end server and just scale backend servers as required. For example, with PHP your front-end server can serve 100k/sec, having X DB backends and Y memcached backends. With a C application, the front end can serve, say, 1M/sec. You still get to keep one front-end, even though you had to put more backends.

    In short, you can significantly reduce the number of servers required if the app was written in C.

    1. Re:A C app would be much faster by philipmather · · Score: 0

      1. http://uk2.php.net/manual/en/intro.apc.php

      Can't be bothered reading the rest of your post, real men use assembler.

      --
      Regards, Phil
    2. Re:A C app would be much faster by Fished · · Score: 1

      You're absolutely right. IF companies could identify, employ, and retain alpha-level coders for their entire development force. They can't. The reality is that unless you're one of the alpha geeks (say in the 90th percentile or better) dynamic languages are better than C, C++, etc. This may change though as we see massive deployments of applications at company expense and data center power costs become a huge issue. For example, Google finds it worthwhile to retain really brilliant developers and seems to be using more C/C++ as times goes on (although they still use plenty of Python.) Personally, I think *some* functional language is going to be the next big thing--and those who can make useful web apps in such a language will be in huge demand.

      --
      "He who would learn astronomy, and other recondite arts, let him go elsewhere. " -- John Calvin, commenting on Genesis 1
    3. Re:A C app would be much faster by ZerdZerd · · Score: 2, Informative

      The proposed ratio of 1:10 is real, if not bigger. And here's why:

      1.) For each request, PHP has to load entire application responsible for that particular response, including its configuration, etc. With memcache(d), you have to instantiate connection classes and reconfigure them, per request. Languages like C/C++, Python and Ruby have different architecture to begin with. They load ONCE and each request triggers a FUNCTION or METHOD of a class, with all the app-specific configuration, db and memcached connections done and configured on app init, NOT per request.

      With caches like APC, overhead is very much mitigated. PHP can also use a pool of connections to memcache/database to minimize connection delays.

      2.) TFA mentions microsecond relevance! Even a simple echo "Hello World" will take much more time than similar action in C. I have yet to see a PHP helloworld app that does it in under 1msec, let alone the microseconds required.

      helloworld.php takes 0.363ms on average here on my laptop.

      3.) Arrays in PHP are slow, being always hashmaps. Other data structures can speed up things. You don't always need hashmaps. SPLFixedArray() is a joke, btw, and available only as of 5.3. Can't compare it to a vector anyways, and lots of fixed structures can be represented by structs or classes in C which are anways faster than in PHP. Also the app can instantiate them once on init, and just (re)load when required.

      PHP can also instantiate it once, with the use of APC cache. It caches opcodes (and thereby constant values/arrays), and you can also cache any data you want, and loading that data is fast since APC is written in C (some small overhead).

      4.) Even if all the app does it parse input vars and call memcache(d) / database funcs/methods to retrieve/store data, those calls are faster in C. Params can be parsed quicker in C, not requiring hashmaps for instance.

      Is waiting on I/O in C faster than in PHP? Nope. So if you're mainly doing database lookups you'll see extremely low speedup porting your code to C.

      5.) FastCGI is crap. If this app were to be done in C, then it would require its own HTTP layer, epoll based (for Linux). It can take out all the crap in HTTP that is not requred to parse the AJAX calls, and does not need to be "generic" enough to deliver static content.

      I know. I'd like to get rid of that crap too. But is it really worth it? Making a very efficient server with all the capabilities your application has now, with all the error checking, testing and security protections would take months. HTTP is more complicated than you'd think.. Is the small speedup you'd gain, versus the maintenance of a much larger application worth it?

      6.) For such dedicated and distributed deployments, garbage collection is sometimes not required. For instace, fixed-length stuctures can be preallocated upon app init, and the app can really take as much RAM as possible on startup. Yes, that would limit the MAX number of users/connections per server, but so what? The app dominates the server, nothing else is required to run (except basic OS environment for the app), so fixed memory consumption is not a problem.

      7.) Even though each request has to wait for I/O of some sorts, either from memcache(d), from disk or from DB, you can process much more of these per front-end server and just scale backend servers as required. For example, with PHP your front-end server can serve 100k/sec, having X DB backends and Y memcached backends. With a C application, the front end can serve, say, 1M/sec. You still get to keep one front-end, even though you had to put more backends.

      In short, you can significantly reduce the number of servers required if the app was written in C.

      You're pulling those numbers out of thin air. You sti

      --
      I'm not insane! My mother had me tested.
  47. Second article ignores the first article. by Vellmont · · Score: 1

    The first article is actually rather good. It focuses on what most of us suspect is the larger architectural challenge, the database,IO, and scaling components not originally designed for a much larger scale. Lessons learned are avoiding joins, reducing IO requests, avoiding DBs for static data, etc. PHP is mentioned as the presentation layer, and optimizations are architectural, not switching languages. Criticisms of PHP are not ones of performance, but ones of maintainability, programming practices, and integrating with C++ code.

    I can't read the second article because it's slashdotted, but the summary of it leads me to believe the author either completely ignored the first article, or didn't understand it at all. I won't re-hash the "Where the fuck did 10:1 come from?" arguments everyone else is very correctly bringing up. But I would like to point out that the author of the second article doesn't sound like he/she has a good grasp of what the first article says.

    --
    AccountKiller
  48. I'm so glad that you thought if this by fridaynightsmoke · · Score: 1

    and Facebook didn't. Facebook has no interest whatsoever in minimising their power usage (electricity is free, you see) and like all corporations they never look for ways of minimising their costs. There are no possible reasons why FB may operate their servers in this way.

    It reminds me of when certain people start raging about the fact that "x% of trucks on the road are EMPTY!!". Yeah, because the big trucking firms apparently don't have rooms full of people whose job it is to make sure that the trucks are as full as possible, because trucks, diesel and drivers are free.

    --
    This is a substitute for a clever sig that fits within the maximum number of characters.
  49. Completely Myopic and One-dimensional Thinking by fooslacker · · Score: 1

    Sadly I couldn't RTFA because of the good old Slashdot effect but the concept that efficiency can be determined by a direct correlation to performance metrics is just wrong.

    For the sake of argument I'll confine my examples of why I believe this thinking is flawed to just the language vs language issue and not bring in any network, database, etc. issues. First, how many more computer hours did it take to build in C++ than PHP? Second if you build like for like functionality in C++ at a given point in time it probably isn't as flexible and maintainable so all maintenance takes longer. Now lets assume you do things "right" and build in all sorts of flexibility and injection points eventually you end up building a higher level abstraction (or perhaps even an full interpreted language) which has the same issues as PHP regarding performance.

    The reason you accept performance declines associated with higher level abstractions is that it allows you to do more in a shorter amount of time at a still reasonable performance level and anyone who doesn't understand that and all the impacts of that certainly can't produce a legitimate analysis of power consumption based on languages. If the author really believes this he should program everything in assembly or even better build specialty hardware for every computing task or better yet simply quit using computers or electricity all together, that will definitely have a bigger impact.

  50. Trade-offs by Nihixul · · Score: 1

    What about the environmental trade-offs inherent in spending time considering this sort of environmental impact versus spending time considering more significant environmental and conservational issues?

  51. Those in Glass Houses Shouldn't Throw Stones by riffzifnab · · Score: 1

    Looks like he should re-write his webserver in C++ so it's not slashdotted so easily.

    1. Re:Those in Glass Houses Shouldn't Throw Stones by belthize · · Score: 1

      I think he did a study that showed if he powered it down 21.6 hours a day he'd save 90% of his energy bill.

    2. Re:Those in Glass Houses Shouldn't Throw Stones by Anonymous Coward · · Score: 0

      That site was already eating "its own dog food":

      The whole thing was written in C++ using their Wt toolkit - the complete source code (of their website) is even available in the public git repo!

      So let's hope they had the profiling build deployed before the "fist of slashdot" hit the app server - it's a single virtual host somewhere in Belgium ;-)
      Really looking forward to some "optimization commits" in the next few days *ggg*

  52. This is stupid by Fnkmaster · · Score: 2, Insightful

    Companies use PHP to develop and run web app functionality because it saves them huge amounts of time and money over rolling out the same thing if you were to write it all in C++. Realize what the cost structure of a company like Facebook is - the amount they pay their engineers, marketing personnel, and so on is significantly more than their amortized server expenses and server operating expenses (including energy costs, etc.).

    Furthermore, the 10x speedup assumption seems ridiculous - how much time is spent on their server in compute-intensive PHP loops where huge gains would be made from switching to C++? And how much of the "code" is really database queries of various sorts? Furthermore, you can generally isolate small areas like that in your codebase and rewrite them as modules in C or C++ to be invoked from PHP land - and if they could easily cut their server expenses even in half (let alone by 90%) by having a few engineers spend a few weeks rewriting some components, don't you imagine they've probably set about doing that already?

    Re-casting a discussion in terms of greenhouse gas emissions or energy use doesn't change any of this - saving energy generally means saving money, unless it takes more expensive resources (such as 100s of humans, who have to spend hundreds of months re-writing code in C++, while they, their families, and dependents emit tons upon tons of greenhouse gases, use electricity, buy groceries, and so-on and so-forth). The cheapest solution certainly isn't always the most environmentally friendly solution (such as when negative externalities are involved - lower labor and pollution standards in China, for example, that make a less "green" product manufactured there less costly in the US), but a vastly more expensive solution that no company in its right mind would implement isn't necessarily greener just because it might save some electricity and a few servers once it was implemented.

    1. Re:This is stupid by butlerm · · Score: 1

      Realize what the cost structure of a company like Facebook is - the amount they pay their engineers, marketing personnel, and so on is significantly more than their amortized server expenses and server operating expenses

      This is *much* less true for a company with tens of thousands of servers than it is for a company with hundreds of servers. As a consequence writing heavily used code in C++ has much greater benefits for large Internet companies than for small ones.

  53. Economics, my friend! by Anonymous Coward · · Score: 1, Insightful

    Obviously lesser number of servers for a lesser CO2 footprint also means cheaper server infrastructure. If that was the case, don't you think FB would have done it long ago? Economic forces are the main drivers of technology innovation in social networking!

  54. Assumptions by Stan+Vassilev · · Score: 1

    As they only say that 'the bulk' is running PHP, let's assume this to be 25,000 of the 30,000. If C++ would have been used instead of PHP, then 22,500 servers could be powered down ( assuming a conservative ratio of 10 for the efficiency of C++ versus PHP code)

    In order to keep math simple, let's assume a horse is a perfect sphere...

    1. Re:Assumptions by smellotron · · Score: 1

      In order to keep math simple, let's assume a horse is a perfect sphere...

      I once wrote a raytracer! It only works for algebraic surfaces like cones, torii, and horses.

  55. It should be C by Tony · · Score: 1

    Cool. Then C would be even faster. It should all be written in C.

    --
    Microsoft is to software what Budweiser is to beer.
    1. Re:It should be C by luzr · · Score: 1

      Actually, no. C does not have templates and inlines are a little bit more limited.

  56. Pot, meet kettle by Tony · · Score: 1

    Yes yes, very nice. Now make the language not shit, please.

    This, in a discussion of C++?

    --
    Microsoft is to software what Budweiser is to beer.
  57. Megatroll by Vexorian · · Score: 1

    blah, this is the sort of troll that makes us c++ lovers look so bad :(

    --

    Copyright infringement is "piracy" in the same way DRM is "consumer rape"
  58. TFA is full of crap by Dumnezeu · · Score: 1

    Nobody takes into consideration the serious environmental impact of C++ over PHP when it comes to designing, implementing and debugging applications, which take much more time and stress people more. They eat more, they shit more, they breath faster, they need to spend more time working and most of them don't live close enough to the office to walk so they either drive or use public transportation. It takes a lot longer to learn C++ than PHP, therefore the developers will be wasting a lot of time without actually producing anything. Why would PHP be 10 times slower than C++ on the web, when most of the work is done by the [most likely written in C] database engine?

    In short: TFA is comparing apples to oranges and says that oranges have 10 times more juice than apples after particularly squeezing that exact amount from them.

    --
    Yes, it's sarcasm. Deal with it!
  59. Oh, the agony . . . by npsimons · · Score: 1

    As they only say that 'the bulk' is running PHP, let's assume this to be 25,000 of the 30,000. If C++ would have been used instead of PHP, then 22,500 servers could be powered down (assuming a conservative ratio of 10 for the efficiency of C++ versus PHP code), or a reduction of 49,000 tons of CO2 per year.

    Before I even start, let me just say I am a C/C++ coder, I've never really touched PHP, and if I were going for a more abstract language, PHP probably wouldn't be it (mind you, I've not written off PHP altogether; I rarely do that with programming languages, except for FORTRAN, COBOL and C#). I've got no favoritism towards languages; I use what best fits the task and try to make my software as readable and maintainable as possible.

    First: where did these numbers come from? I find it hard to believe them, as I have seen actual benchmarks of PHP, not just WAG of "10 times as slow as C++".

    Second: if the author is so worried about PHP being inefficient, why doesn't he help improve the efficiency of the interpreter? Remember, there are no efficient languages, only efficient implementations.

    Third: has he even factored in the fact that higher level languages require less total development time? What about all those commuting hours saved by the programmers because they weren't having to run their PHP scripts through valgrind's memcheck?

    Fourth: why C++? How about FORTRAN or assembler? FORTRAN compilers are extremely good at optimizing code, and I'm sure you could squeeze out a few more cycles by coding it in assembly.

    1. Re:Oh, the agony . . . by Anonymous Coward · · Score: 0

      Before I even start, let me just say I am a C/C++ coder

      If you call it "C/C++" then you can't be a very good one.

    2. Re:Oh, the agony . . . by bdrewery · · Score: 0

      On top of that, if anyone RTFA, they would see this was just an advertisement for his C++ web framework. Checkout that 'Hello World' app!

    3. Re:Oh, the agony . . . by npsimons · · Score: 1

      First: where did these numbers come from? I find it hard to believe them, as I have seen actual benchmarks of PHP, not just WAG of "10 times as slow as C++".

      My bad; I can't seem to see TFA right now, but judging from other comments, the author actually did use the language shootout benchmarks. My other points still stand, however, as well as points made by others: how much of Facebook's web serving is CPU (in PHP) bound? Did the author take into account the possibility that with caching, PHP wouldn't be nearly so slow?

      In my (admittedly limited) experience as a (mostly) maintenance programmer, the absolute number one priority in writing software should be to write maintainable code, for two reasons: 1) it will have to be maintained, and 2) technology (not just hardware) will improve such that "efficient code" that is unreadable will ultimately become just unreadable; simple, straightforward, maintainable code will be optimized by the interpreter or compiler to be as efficient if not more efficient than the "efficient code".

    4. Re:Oh, the agony . . . by npsimons · · Score: 1

      On top of that, if anyone RTFA, they would see this was just an advertisement for his C++ web framework. Checkout that 'Hello World' app!

      If anyone could RTFA. It appears to be slashdotted. I suspected the author had an agenda, but ad hominem is not a valid way to debate the merits of an idea. I'd still like to know where he got his numbers; the language shootout lists the factor of pure CPU bound PHP vs C++ as somewhere between 2x and 96x depending on the algorithm; this is ignoring things like caching, pre-compiling, etc. Also of interest is the fact that it takes anywhere between 1/7 and 1/2 as many lines of code in PHP vs C++ for the same algorithm; which again, does not even take into account the time to debug, eg memory errors.

  60. But the same argument could apply by Tony · · Score: 3, Insightful

    Yes. I know the difference. C is an elegant if simple language, which is hard to program properly. C++ is an abomination that attempted to take the elegant, simple nature of C by bolting on spare body parts from dead object-oriented corpses, resulting in a language that is neither simple nor elegant, which is even harder to program properly.

    See, I know the difference.

    But if the point is to gain efficiency, why would you stop at C++? It's not a magical perfect balance of performance with elegance. C would give better performance than C++.

    Sure, there's the non-OO tradeoff (though you could quite easily gain the benefits of OO, though not as elegantly as C++), and then you don't have to deal with fucking templates (which are really nice to program, but a bitch to clean up when someone else has fucked them up for you).

    The premise of the article is stupid, and shows a pure lack of understanding of PHP, web service architecture and implementation, and a not-inconsiderable dose of C++ fanboi-ism.

    --
    Microsoft is to software what Budweiser is to beer.
  61. Words of Wisdom by Anonymous Coward · · Score: 0

    To paraphrase Heinlein, who cares if the answer takes a microsecond or a nanosecond as long as it's correct.

  62. Not entirely true by chord.wav · · Score: 1

    Assuming that the average C++ coder is heavier and bigger in size (even when shaved) that the average PHP coder, I think the exhalation of CO2 produced by the C++ programmers needed for the job overpower the 10:1 edge they have on code speed.
    Also, they probably eat more, and drink more coffee, which turns into a bigger environmental footprint if you count the emissions produced by trucks that deliver those groceries to the nearest store. And, just to name one example: Let's assume that 50% of the coffee company employees drive to their work and so on....

    Hey, they are the ones who started drawing conclusions based on assumptions, not me.

  63. Couldn't they just turn off all of those servers? by vorlich · · Score: 1

    After all, what purpose do they really serve? Apart from fans of X Factor would anyone really notice if it was gone?
    At the very least it would save us all from the annual slashdot Christmas bunfight over which code reigns supreme.

    --
    Posts, MyBio or Sig, may contain satire, sarcasm, bolded nouns be sardonic or even witty & be Church of SD
  64. Premature Optimization by mortonda · · Score: 1

    Dumb statements like this is what leads to premature optimization. Show me the proof: Put a profiler on facebook and show me where the bulk of code execution is happening. I seriously doubt one could code a similar app in C++ and make it run smoothly and stable and yet save that many servers.

  65. Maybe reduce MHz/#CPU, not server count by redelm · · Score: 1

    If the goal is energy conservation, the server count might be not be reduceable -- # required for memory, network ports, disk seekers, or other things.

    However, it is _certainly_ possible to reduce power and cooling requirements somewhat with less inefficient code. So you can install slower/lowerV/lowerW CPUs, or fewer cores (unless you are already at min). Or at least the CPUs spend more time in powersavings states.

    The power reduction may not be all that great, ~20W per server, but over 25,000 , that is still 5 MW -- 4.4 M$/yr

    Beware of false economies -- LoC does not matter if those lines are rarely executed. What runs often matters. What doesn't might not be worth the power investment of compilation.

  66. Figures off by a factor of 10 to 100 by tomhudson · · Score: 2, Informative

    My own experience doing server development in c was that it's a minimum of 30:1 (and in in some cases, much greater). Plus the speed differential is huge, and also in favour of c.

    There's a big difference between a couple of hundred requests a second and 6,000 - 10,000.

    Then again, the php code had to be served through apache, while the c code was served directly by a custom server sitting on a separate socket, so there's no telling how much of the overhead was from apache.

    Even the absolute worst-case scenarios were well over 10:1.

    1. Re:Figures off by a factor of 10 to 100 by 91degrees · · Score: 1

      C is faster, and I have no reason to doubt your figures for applications that are written entirely in compiled low level languages. Are you factoring in the amount of work done by mySQL? I expect that's actually a fair chunk of the CPU time and I believe that is written in C.

    2. Re:Figures off by a factor of 10 to 100 by tomhudson · · Score: 3, Informative

      Those were actual benchmarks run at peak load for 5-minute periods. sustained rate of over 600,000 queries in 5 minutes, or 2,000 per second (around 2,200 iirc), on absolutely craptastic hardware, against an 8 gig mysql table. Benchmark was by running ab (apache benchmark) against a custom forking server instead of apache, tested with between 100 and 400 simultaneous requests. Threads were never "reaped", always reused, so it was important that there were no memory leaks, but never having to spawn another thread after initial startup also contributed to the difference.

      Contrast to php, where every script has to be loaded, interpreted, then flushed out of the system so it leaves a clean memory footprint for the next script, and where tons of variables that your script may never call have to be initialized each run. Obviously only compiling what you need and loading it once is more efficient :-)

    3. Re:Figures off by a factor of 10 to 100 by Waffle+Iron · · Score: 1

      Even the absolute worst-case scenarios were well over 10:1.

      Web apps are usually mostly string manipulation. Scripting languages have high-level primitives for string manipulation that are themselves written in C. So the difference may not be that much at all.

      I've done quite a bit of benchmarking on string operations and container frameworks. You can make C go ultra fast if you write custom containers, dangerous memory strategies and string handling code for the target problem. However, a site like Facebook wouldn't exist if it had to wait while people laboriously write and debug that kind of code. You might as well use assembly language.

      In the real world, people will use C++/STL as the default "high performance" implementation. For string and container operations, the STL usually doesn't really end up being any faster than Java or similar languages, and even scripting languages are competitive in some cases. (If they have to stick with C, they'd use something like glib to keep their sanity. That's even slower.)

    4. Re:Figures off by a factor of 10 to 100 by Bodrius · · Score: 2, Insightful

      What kind of work were those 10K req/sec on your own custom server doing? Was it a standard db-backed web app, or something more specialized and computationally intensive?

      Not that I doubt the difference you saw - but I'm still skeptical of the 10:1 factor as applied to Facebook servers, which seem relatively standard webapp cycle (request -> datastore lookup -> html), *just from the programming language*.

      Admittedly, I don't do PHP, so the language could be as bad and impossible to scale as you claim. But from their architecture description, I really doubt the request spends enough time (>= 90%?) in PHP computation to make *any* change there translate into a 10X improvement.

      At least on my own experience, once you get into the '~1K req/sec' scenario on that type of webapp, the middle-tier code is rarely your main perf headache. You spend more of your time ensuring your data sources (sql+cache + any other services) keep up, and your middle-tier code spends much of its time waiting for whatever went out the socket to come back. There is always some perf improvement to make on the middle-tier, but if the request spends 90% of its time on the presentation layer... well, that's usually a perf bug, not by design.

      There are good reasons to justify the cost of switching away from PHP - and they seem to be aware of them. But order-of-magnitude perf improvements would more likely result from architectural and datastore improvements - and sensibly enough, that seems where their efforts have focused.

      --
      Freedom is the freedom to say 2+2=4, everything else follows...
    5. Re:Figures off by a factor of 10 to 100 by bytesex · · Score: 1

      Seconded; I wrote many websites over and over in perl and C. I found that perl is generally ten times slower than C, while PHP was about three times slower than perl. And that includes everything: data access, I/O, and number crunching.

      --
      Religion is what happens when nature strikes and groupthink goes wrong.
    6. Re:Figures off by a factor of 10 to 100 by tomhudson · · Score: 1

      I'm glad to see you put "high performance" in quotes wrt the STL. The STL is *not* optimal for anything, and especially not for string ops. My own benchmarks showed it to be at least 4 TIMES slower than a custom class. It seems that the thought of writing even a simple container or string class scares the crap out of people nowadays. And $_DIETY forbid that you try to do it with a collection of functions and a few structs in straight c.

      And if you're writing threaded code, you can't really use the stl anyway. (I know, someone's going to mention proprietary versions of the stl that support finer-grained locking primitives, but even that's not anywhere near optimal).

    7. Re:Figures off by a factor of 10 to 100 by tomhudson · · Score: 1

      one example, parsing out requests formatted in xml, merging up to 120 different bids/prices from a database, etc.

      There's no way a scripting language can ever come within even 10% of a properly written custom c solution. It will simply never happen.

    8. Re:Figures off by a factor of 10 to 100 by Waffle+Iron · · Score: 1

      It seems that the thought of writing even a simple container or string class scares the crap out of people nowadays.

      It should, because a bunch of incompatible framework classes sucks ass. A long time ago I was involved with a project that over time accumulated a combination of MFC stuff, COM wrappers, STL and our own custom strings and containers. Huge chunks of code did nothing but convert between the various formats. Never again will I get involved with reinventing wheels like that. I'll take the performance hit.

    9. Re:Figures off by a factor of 10 to 100 by tomhudson · · Score: 1

      It's pretty bad when shelling out is quicker by a factor of 10. Running your c app directly in your server instead of as an external cgi means you save even that overhead - so add in another 10x improvement. Run it in a custom server instead of a generic one like apache, and save even more time.

      Unfortunately, that will never happen because most "programmers" can't do anything much beyond memory-managed scripting (which isn't "real programming" - it's scripting - but that's another argument for another day).

    10. Re:Figures off by a factor of 10 to 100 by ls671 · · Score: 1

      > a bunch of incompatible framework classes sucks ass

      Agreed,

      Note that I have never encountered a custom written string framework while using Java, which is good. Let the optimization be taken of by the JVM and the compiler and the JIT.

      I wonder if it is still required to use StringBuffer/StringBuilder instead of += while doing several concatenation to the same original string in order to achieve maximum performance or if they have managed to optimize that too by now ! ;-)

      I still use StringBuilders anyway... ;-)
       

      --
      Everything I write is lies, read between the lines.
    11. Re:Figures off by a factor of 10 to 100 by grepya · · Score: 1

      "And if you're writing threaded code you can't really use the stl anyway"

            Oh noooz... I must recall the thousands of lines of multhreaded code I wrote for various server appliances using all sorts of std library containers and algorithms (running on 100's of customer sites) right away. Why didn't you warn us about this menace before.

        Seriously why would you so confidently spread blatant FUD ? Care to explain why "threaded code" (I presume you mean multithreaded programs) can't use the c++ standard library (yes... what used to be called STL is now almost completely subsumed in the standard library).

      "I know, someone's going to mention proprietary versions of the stl that support finer-grained locking primitives, but even that's not anywhere near optimal"

          So many questions about that statement:
      1) what is "optimal" ?
      2) why do you assume that "finer grained locking" would be more optimal (by whatever your definition of "optimal" is.
      3) and finally, what benchamarks or data do you have to support your general dismissal of standard library containers in multithreaded code and your more specific claim 2 ?
       

    12. Re:Figures off by a factor of 10 to 100 by tomhudson · · Score: 1

      1. For this discussion, I think optimal == fewer resources needed (time, ram, etc).

      2. The locking primitives in the STL aren't fine-grained. Fine-grained locking gives more chance for your thread to use up its complete timeslice rather than have to wait because another thread is holding onto the "Big F****** Lock" for some shared resource. Additionally, you take a performance hit using the STL because stl classes have virtual method lookup tables. C code doesn't have virtual method lookup tables so it runs quicker.

      3. As for the benchmarks, I benchmarked it personally to prove to all the windows weenies that the STL had no place in what we were trying to do, which was a server running on bsd unix - my c99 code was a MINIMUM of 4 times faster than the same code using the stl and c++.

      The stl is not part of the c standard and never will be. I bought a hardcover copy of TR1 to see if it would finally give me reason to adopt the stl - it didn't, but at least I no longer wonder if I should bother with it. Maybe one day I'll find something that begs for it to be used, in which case sure, then I'll just use it ... but until then, it doesn't offer me anything special and to be honest I find it aesthetically ugly. If it weren't so ugly-looking, I'd probably be less inclined to throw rocks at it - which means I probably wouldn't have written the benchmarks and just assumed that it was "almost as fast."

      Please don't get me wrong - I like c++ as much as c. Classes can be a beautiful thing. But not all the time. The biggest mistake of Java was to try to make everything a class (the second-biggest was not to have a macro processor, but that's okay ... there are ways around both limitations :-)

    13. Re:Figures off by a factor of 10 to 100 by sopssa · · Score: 2, Interesting

      Contrast to php, where every script has to be loaded, interpreted, then flushed out of the system so it leaves a clean memory footprint for the next script, and where tons of variables that your script may never call have to be initialized each run. Obviously only compiling what you need and loading it once is more efficient :-)

      You're forgetting all the php optimizers, script and chunks of code caching in bytecode and ram caching of scripts. These make a major difference, but are probably just used on larger websites (like on facebook)

    14. Re:Figures off by a factor of 10 to 100 by Simon80 · · Score: 1

      Which STL classes have vtables? The T in STL stands for template.

    15. Re:Figures off by a factor of 10 to 100 by snemarch · · Score: 1

      You're not suggesting it's a good idea to use synchronization directly in collection/string code, are you? O_o The original JAVA collections (like vector) were synchronized - there's a pretty good reason the new-style (like arraylist) collections aren't. Just like BigLocks are bad for threaded performance, so is trying to do synchronizing on a too low level.

      --
      Coffee-driven development.
    16. Re:Figures off by a factor of 10 to 100 by testadicazzo · · Score: 1
      People seem to be missing the point of the OP.

      If you're goal is to get a prototype, or low demand app out the door quickly, PHP is a much better choice than C++. But if you're a mega user like Facebook or google, maybe it becomes worthwhile to handcode custom containers, even do a little assembly, etc, focusing on machine efficiency rather than development efficiency. How can you tell whether this would be a good investment? Look at how many servers you could shut down: monetary savings, plus it's good for the environment.

      Whether or not the original posters estimate is a good one, may be open to debate (although in my experience his estimate is conservative wrt to performance improvements). It's interesting food for thought though, and should be investigated further by large scale operators like Facebook, Google, Amazon...

    17. Re:Figures off by a factor of 10 to 100 by testadicazzo · · Score: 1

      Additionally, you take a performance hit using the STL because stl classes have virtual method lookup tables.

      Well, here you show that you form and express opinions even when you don't know what you are talking about. The whole point of Templates is the work gets done at compile time, not at runtime. no vtables.

      As for your benchmarks, STL has nothing to do with windows, so I don't understand why you want to prove anything to windows wienies wrt to the STL. But your psychological picaddiloes are your business. More than likely though your benchmarks are foolish.

      Since you don't understand how the STL works (i.e. you think it is based on inheritence and vtables, which is wrong), you probably used it badly. So that's an obvious potential source of skew in your benchmarks. Secondly, I could easily write a benchmark that would make my hand code beat the STL, or write code that beats an STL implementation for a given benchmark. That doesn't say anything about the real world performance however. The STL provides wonderful results for a wide range of applications, but it doesn't neccisarily provide the ideal solution for a particular problem. It's a wonderful tool, and if you know how to use it correctly, it will provide you wonderful benifits in your code. I personally would never hire a programmer who is unwilling to use, and unwilling to learn how to use the STL.

      B. Stroustrup agrees that String class isn't perfect, as a result of trying to be very general, but I would still think carefully before rolling my own string class. But you don't have to use the string class to use the STL.

      You don't need to be reading TR1, as you clearly aren't unerstanding it. I would suggest Scott Meyers "Effective STL" if you're interested in correcting this glaring shortcoming in your C++ expertise. If you don't understand the STL please don't call yourself a C++ programmer.

      I agree with you about java though.

    18. Re:Figures off by a factor of 10 to 100 by tolan-b · · Score: 1

      > Contrast to php, where every script has to be
      > loaded, interpreted, then flushed out of the
      > system so it leaves a clean memory footprint for
      > the next script, and where tons of variables that
      > your script may never call have to be initialized
      > each run. Obviously only compiling what you need
      > and loading it once is more efficient :-)

      With APC, which Facebook uses, the scripts are compiled to bytecode once then cached in memory. APC also provides a nice interface to PHP's SHM functionality and allows you to keep many of your variables there, which Facebook also does. FB use APC SHM as first level cache and Memcached as second level cache.

    19. Re:Figures off by a factor of 10 to 100 by tolan-b · · Score: 1

      Parsing XML would be handled by a PHP extension, which would be... written in C!

    20. Re:Figures off by a factor of 10 to 100 by Halotron1 · · Score: 1

      Then again, the php code had to be served through apache, while the c code was served directly by a custom server sitting on a separate socket, so there's no telling how much of the overhead was from apache.

      My thoughts exactly. Is the bottleneck the webserver or the actual code?
      Seems more likely that the number of servers has to do with the massive number of requests that have to be handled, so they would need several webfarms, etc., and since they have users all over the world they would have more than one data center.

      From a source for the article:
      Given its global user population, Facebook eventually had to move to replicating its content across multiple data centers. Facebook now runs two large data centers, one on the West coast of the US and one on the East coast.

      So cut your 30,000 servers in half to 15,000 servers per data center.

    21. Re:Figures off by a factor of 10 to 100 by tomhudson · · Score: 1

      No, I'm not forgetting any of that. The bytecode still has to be interpreted at runtime (same as all those "templating engines" don't really compile code - look at their output - it's not machine code). Ram caching of scripts (or even using an object cache) doesn't help that much either - you STILL are running an interpreter. Until the optimizer outputs machne code (not "byte-code", which is not capable of being run directly by the cpu), it will always be slower than c.

    22. Re:Figures off by a factor of 10 to 100 by tomhudson · · Score: 1

      Any program that uses the stl is going to be a c++ program by definition. It will have classes that use the stl (how often do you see a c++ program with no classes?), and since most people don't write one-off classes, and you have to guard access to the stl with locking primitives anyway (STL_LOCK, STL_UNLOCK) which the programmer usually stuffs into a class and then derives their objects so that they don't have to worry about locking, it's pretty much inevitable that you'll end up with vtables in your runtime when you use the stl.

      Hey, I didn't write that code - I just nuked it wherever possible because it is fugly; Besides, the STL doesn't really belong in an OOP environment - even Stephanov agrees that the STL is not OOP., so no wonder it looks ugly.

      Yes. STL is not object oriented. I think that object orientedness is almost as much of a hoax as Artificial Intelligence. I have yet to see an interesting piece of code that comes from these OO people. In a sense, I am unfair to AI: I learned a lot of stuff from the MIT AI Lab crowd, they have done some really fundamental work: Bill Gosper's Hakmem is one of the best things for a programmer to read. AI might not have had a serious foundation, but it produced Gosper and Stallman (Emacs), Moses (Macsyma) and Sussman (Scheme, together with Guy Steele). I find OOP technically unsound. It attempts to decompose the world in terms of interfaces that vary on a single type. To deal with the real problems you need multisorted algebras - families of interfaces that span multiple types. I find OOP philosophically unsound. It claims that everything is an object. Even if it is true it is not very interesting - saying that everything is an object is saying nothing at all. I find OOP methodologically wrong. It starts with classes. It is as if mathematicians would start with axioms. You do not start with axioms - you start with proofs. Only when you have found a bunch of related proofs, can you come up with axioms. You end with axioms. The same thing is true in programming: you have to start with interesting algorithms. Only when you understand them well, can you come up with an interface that will let them work.

      But back "sort of" on topic - how often have you seen a non-trivial c++ program that used the stl that didn't also use inheritance?

    23. Re:Figures off by a factor of 10 to 100 by tomhudson · · Score: 1

      The problem is always one of access rights - chunk of code a says "I want the next item in the list", gets suspended, chunk of code b says "delete the last item", chunk of code a resumes and gets back a pointer to non-valid data. The traditional way to solve this is to lock on $SOMETHING. Other work-arounds are for the runtime environment to guarantee to the programmer that certain statements will get executed atomically, so you can guarantee setting/clearing a flag, or changing a function pointer (but what happens when two processes BOTH try to set two flags and each one only sets one ... so you end up with having to either put in code to detect a deadlock, or you end up with a 3rd flag that guards the first two, which wrecks code that isn't aware of the 3rd flag, so you end up with a real mess anyways and say "what the heck, let's just remove the first two flags and check only the third" so you're not so fine-grained. Done often enough, you end up back at the "one big lock" level).

      In the end it depends on the application you're writing, and whether data that's slightly "dirty" is okay.

    24. Re:Figures off by a factor of 10 to 100 by lamapper · · Score: 1

      2. The locking primitives in the STL aren't fine-grained. Fine-grained locking gives more chance for your thread to use up its complete timeslice rather than have to wait because another thread is holding onto the "Big F****** Lock" for some shared resource. Additionally, you take a performance hit using the STL because stl classes have virtual method lookup tables. C code doesn't have virtual method lookup tables so it runs quicker.

      3. As for the benchmarks, I benchmarked it personally to prove to all the windows weenies that the STL had no place in what we were trying to do, which was a server running on bsd unix - my c99 code was a MINIMUM of 4 times faster than the same code using the stl and c++.

      Great post and first hand actual experience. The only kind that is ultimately respectable as too much marketing FUD gets in the way. (Both Java and CMS come to mind with respects to marketing FUD)

      Please don't get me wrong - I like c++ as much as c. Classes can be a beautiful thing. But not all the time. The biggest mistake of Java was to try to make everything a class (the second-biggest was not to have a macro processor, but that's okay ... there are ways around both limitations :-)

      Java will have its place, just not everywhere! Java will never be faster than alternative solutions that are optimized, just accept it. And reusable code is great, but not if it is recreating code that already works and exists in a faster lower level on the server. I learned this the hard way when writing MVC controllers in PHP, sorry but why do I need to re-write functionality that exists already in apache and http in Object Oriented PHP...of course the MVC is going to be slower...

      I like that you took the time to benchmark and get the facts first hand. Cuts through the BS that people always throw out there. Yes language X is faster if you spend thousands of dollars on extra memory and memory cache tools that you do not make available to language Y, another duh moment there.

      To date, no .NET solution or IIS server solution can touch Linux and better solutions. No amount of wining, no pun intended, can change the facts of this. And as for scaling the same is true. Else you would see Microsoft servers at one of the many financial exchanges around the world, but they lost their last one last year didn't they. Another duh moment.

      --
      Is your Internet Throttled? Install DD-Wrt, OpenWRT or Tomato to learn the truth! Google: 1Gbps/1Gbps: 5 Communities
    25. Re:Figures off by a factor of 10 to 100 by snemarch · · Score: 1

      I'm not saying you shouldn't synchronize, but that adding synchronization to your containers is the entirely wrong granularity to do it - ask yourself what's more efficient: lock, 500 inserts, unlock... or 500 times lock-insert-unlock? The latter is impossible if you add synchronization at the primitive container level.

      You should probably move up a notch on the abstraction level ladder :), and not deal directly with primitive containers from client code.

      Apart from simple mutexes, there's other things to consider like lockfree algorithms, reader/writer locks, and "divide and conquer" even if it means duplicating data per-thread.

      Synchronization is expensive, sometimes too much, and then you have to restructure your logic.

      --
      Coffee-driven development.
    26. Re:Figures off by a factor of 10 to 100 by tomhudson · · Score: 1

      I have never seen a non-trivial program in THIS universe that uses the stl and doesn't encapsulate it in a class, and then derive from that class. So your code is going to have some vtables, and its going to be slower than straight c, and it's going to be WAY slower than php. What universe do YOU live in where people use the stl but not objects?

    27. Re:Figures off by a factor of 10 to 100 by tomhudson · · Score: 1

      Repeat after me - bytecode needs an interpreter at runtime. It is not "compiled" in any true sense of the word, any more than the output of the c preprocessor could be called "compiled".

      Bytecode is an intermediate representation of your program that is further interpreted at runtime, not compiled code that can be run on a real-world cpu. Your script is translated to bytecode as part of the process, whether it's done in the web server when the script is loaded and run, or via APC. You can see this because certain errors cause the program to not parse during the conversion to bytecode; contrast with logic errors, which will cause it to fail partway through execution.

      This will be slower than c because you're still interpreting at runtime - you've just skipped the "strip out the comments and extraneous whitespace and represent it as bytecodes and references to data" portion.

    28. Re:Figures off by a factor of 10 to 100 by Simon80 · · Score: 1

      Inheritance doesn't result in vtables, virtual functions result in vtables. How often have you seen a non-trivial C program that doesn't use function pointers somewhere? C++ doesn't force you to use virtual functions, and neither does the STL. The whole point of templates is to allow the compiler to perform the specialization at compile time.

      Also, your generalizations about threading in relation to the STL are completely misinformed. The manual for libstdc++, for example, says that:

      All library objects are safe to use in a multithreaded program as long as each thread carefully locks out access by any other thread while it uses any object visible to another thread, i.e., treat library objects like any other shared resource.

      Thus, as long as STL objects aren't shared by more than one thread, no locking is required. If not for the niche subject area, and your low /. UID, I'd think you were trolling. Even if your opinions are valid in relation to past experience, they are extreme, and certainly misplaced today.

    29. Re:Figures off by a factor of 10 to 100 by tomhudson · · Score: 1

      And guess what - it would still be slower, because of the glue code which is run from the interpreter. Also, since we know what data we want, no need to parse it "the right way" - lots of short-cut opportunities. You don't get that with a generic solution.

    30. Re:Figures off by a factor of 10 to 100 by tomhudson · · Score: 1

      lock-free algorithms are HARD to get right :-) Depends on the data, the use you're going to make of it, whether it can be a bit dirty (and you can reliably detect that it's dirty), etc.

      Locking is something you can go crazy by thinking too much about it ... but it's also fascinating.

    31. Re:Figures off by a factor of 10 to 100 by tomhudson · · Score: 1
      The documentation: http://gcc.gnu.org/onlinedocs/libstdc++/manual/using_concurrency.html

      All library objects are safe to use in a multithreaded program as long as each thread carefully locks out access by any other thread while it uses any object visible to another thread, i.e., treat library objects like any other shared resource. In general, this requirement includes both read and write access to objects; unless otherwise documented as safe, do not assume that two threads may access a shared standard library object at the same time.

      All I'm saying is that the STL is not thread-safe, especially when writing server software - which isn't only what I'm writing about, but what the original article is writing about. The STL is also slower - benchmarks prove it. The STL adds complexity, which means more code to debug when something goes haywire. And finally, debugging a multi-threaded app is already a pain to begin with.

      Look, TR1 has some interesting features. It just doesn't have a place in what I was doing, and probably won't in at least the near future. Maybe one day I'll find a need for it, or it will makes something simpler - then I'll use it. (but you have to admit the syntax is visually fugly).

    32. Re:Figures off by a factor of 10 to 100 by snemarch · · Score: 1

      Indeed it is, and personally I'd much rather re-use somebody else's lock-free code than having to write my own ;) - but the potential for savings can be big.

      --
      Coffee-driven development.
    33. Re:Figures off by a factor of 10 to 100 by Pseudonym · · Score: 1

      As for the benchmarks, I benchmarked it personally to prove to all the windows weenies that the STL had no place in what we were trying to do, which was a server running on bsd unix - my c99 code was a MINIMUM of 4 times faster than the same code using the stl and c++.

      I believe your benchmarks, though I would be curious to know about the relative code size and maintainability between the C99 version and the C++/STL version. I'm also curious to know exactly where all that extra time is being spent.

      I believe it because specialised code always wins out over generic code, at the cost of maintainability. It's no different from the PHP vs C++ tradeoff mentioned in TFA. PHP loses you a lot of performance while gaining a lot of "R" in your RAD.

      But still, using STL over custom containers does not automatically result in a 4× performance hit for most applications. The benefit of a standard, generic collection of containers is that you can use it quickly, and rewrite it if and only if profiling determines that it's causing a performance problem.

      And having said that, there are, of course, a few known performance problems in many STL/standard library implementations, such as reference counted strings.

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    34. Re:Figures off by a factor of 10 to 100 by Pseudonym · · Score: 1

      Quite. You're not supposed to inherit from STL classes, unless you REALLY know what you're doing.

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    35. Re:Figures off by a factor of 10 to 100 by tolan-b · · Score: 1

      You said:

      > Contrast to php, where every script has to be
      > loaded, interpreted, then flushed out of the
      > system so it leaves a clean memory footprint for
      > the next script, and where tons of variables that
      > your script may never call have to be initialized
      > each run. Obviously only compiling what you need
      > and loading it once is more efficient :-)

      5 actual items here in the case of PHP, one of which you didn't mention:

      1. Read
      2. Parse
      3. Interpret bytecode
      4. Variable re-interpretation
      5. Flush from memory

      APC removes 1,2,5 and to a large extent 4.

      In the case of 5, yes the execution environment is still cleared, but the bytecode remains in memory in APC.

      I'm not saying it's as fast as hand written C just pointing out that a large part of what you wrote is rubbish in the typical production environment.

    36. Re:Figures off by a factor of 10 to 100 by tolan-b · · Score: 1

      Regarding the glue code, do you honestly think the tiny amount of code required to dump the string into the XML parser is going to make a noticeable difference when compared to the amount of processing required to parse an XML document?

      You write custom XML parsers every time you parse a different doc schema? Wow.. How many C/C++ apps do this? Let's take Debian as a sample and just look at the libxml2 package, provided by Gnome but used by many. Here are the packages dependent on it:

      php5-xsl,libxml2 2.6.27
      php5-xmlrpc,libxml2 2.6.27
      php5-cli,libxml2 2.6.27
      php5-cgi,libxml2 2.6.27
      libapache2-mod-php5,libxml2 2.6.27
      libapache-mod-php5,libxml2 2.6.27
      php4-domxml,libxml2 2.6.27
      php4-imagick,libxml2 2.6.27
      xmlroff,libxml2 2.6.27
      xfce4-mixer,libxml2 2.6.27
      virtualbox-ose,libxml2 2.6.27
      virt-viewer,libxml2 2.6.27
      ure,libxml2 2.6.27
      umbrello,libxml2 2.6.27
      sobby,libxml2 2.6.27
      scribus,libxml2 2.6.27
      quanta,libxml2 2.6.27
      postgresql-contrib-8.3,libxml2 2.6.27
      postgresql-8.3,libxml2 2.6.27
      perlmagick,libxml2 2.6.27
      osm2pgsql,libxml2 2.6.27
      openoffice.org-writer,libxml2 2.6.27
      openoffice.org-core,libxml2 2.6.27
      openbox,libxml2 2.6.27
      obconf,libxml2 2.6.27
      network-manager-vpnc-gnome,libxml2 2.6.27
      mysql-query-browser,libxml2 2.6.27
      mysql-admin,libxml2 2.6.27
      lighttpd-mod-webdav,libxml2 2.6.27
      libwine,libxml2 2.6.27
      libvirt0,libxml2 2.6.27
      libvirt-bin,libxml2 2.6.27
      libpurple0,libxml2 2.6.27
      libobrender16,libxml2 2.6.27
      libobparser16,libxml2 2.6.27
      libmapnik0.5,libxml2 2.6.27
      libmagick10,libxml2 2.6.27
      liblablgtksourceview-ocaml,libxml2 2.6.27
      liblablgtk2-ocaml,libxml2 2.6.27
      liblablgtk2-gnome-ocaml,libxml2 2.6.27
      kxsldbg,libxml2 2.6.27
      kopete,libxml2 2.6.27
      klinkstatus,libxml2 2.6.27
      kdelibs4c2a,libxml2 2.6.27
      juk,libxml2 2.6.27
      icecast2,libxml2 2.6.27
      heartbeat,libxml2 2.6.27
      gtkpod,libxml2 2.6.27
      gpomme,libxml2 2.6.27
      gobby,libxml2 2.6.27
      gnucash,libxml2 2.6.27
      gnash-common,libxml2 2.6.27
      finch,libxml2 2.6.27
      ekiga-gtkonly,libxml2 2.6.27
      ekiga,libxml2 2.6.27
      compiz-plugins,libxml2 2.6.27
      compiz-gnome,libxml2 2.6.27
      compiz-core,libxml2 2.6.27
      collectd,libxml2 2.6.27
      autogen,libxml2 2.6.27
      apt-dater,libxml2 2.6.27
      vlc-nox,libxml2 2.6.27
      python-libxml2,libxml2 2.6.27
      postgresql-contrib-8.1,libxml2 2.6.27
      postgresql-contrib-7.4,libxml2 2.6.27
      php5-xsl,libxml2 2.6.27
      php5-xmlrpc,libxml2 2.6.27
      php5-cli,libxml2 2.6.27
      php5-cgi,libxml2 2.6.27
      perlmagick,libxml2 2.6.27
      openoffice.org-core,libxml2 2.6.27
      network-manager-gnome,libxml2 2.6.27
      libxml2-utils,libxml2 2.5.7-1
      libxml2-utils,libxml2 2.5.7-1
      libxml2-utils,libxml2 2.6.27
      libxml2-dev,libxml2 2.6.6-1
      libxml2-dev,libxml2 2.6.6-1
      libxml2-dev,libxml2 2.6.27.dfsg-6+etch1
      libxml2-db

    37. Re:Figures off by a factor of 10 to 100 by tolan-b · · Score: 1

      He chose a bad example though because Facebook do do their own custom C/C++ development where they see a need for it while keeping presentation code in PHP where it belongs because of the increased flexibility.

    38. Re:Figures off by a factor of 10 to 100 by tolan-b · · Score: 1

      By the way, in your sample app were you parsing that XML with actual PHP code or the XML functions built into the language or available as modules? If it was the former then your benchmarks are worthless as you clearly don't have a clue about how to use PHP.

    39. Re:Figures off by a factor of 10 to 100 by tomhudson · · Score: 1

      I believe it because specialised code always wins out over generic code, at the cost of maintainability. It's no different from the PHP vs C++ tradeoff mentioned in TFA. PHP loses you a lot of performance while gaining a lot of "R" in your RAD.

      And that's the crux of the matter. Not "which is better." I slag the STL because I don't like it, but so what. If it floats peoples boats, who cares. It's ALL about trade-offs. At bottom, the article was about the tradeoff between dev time and run time. When you're running something as big as facebook, the tradeoff calculus is different. They would certainly benefit by moving some of the more stable stuff from php to c - or even c++ and the stl, if that works for them.

      People who think that php is "almost as fast as c" need to rethink their position.

      And yes, reference counting, weak references, etc. Blech!

    40. Re:Figures off by a factor of 10 to 100 by tomhudson · · Score: 1

      I'm not saying it's as fast as hand written C just pointing out that a large part of what you wrote is rubbish in the typical production environment.

      You can't have it both ways. Also, Facebook - which is the example in the article - is not "the typical production environment." So tell us, how is your snide little remark anything but rubbish?

      Also, APC isn't "that" much faster. 4x is nowhere near 10-100x.

    41. Re:Figures off by a factor of 10 to 100 by tomhudson · · Score: 1

      Regarding the glue code, do you honestly think the tiny amount of code required to dump the string into the XML parser is going to make a noticeable difference when compared to the amount of processing required to parse an XML document?

      You write custom XML parsers every time you parse a different doc schema? Wow.

      If I know exactly what the format is, and what data I'm looking for, it's WAY quicker to treat it like a stream of tokens, parsing out tokens, and when you find the beginning of one that interests you, save a pointer to 1 byte past the end, continue tokenizing until you find the close, and grab the data between the saved pointer and the beginning of the end token.

      You can recurse this if you have enclosed tags.

      Why would I want to waste my time doing more? (aside from the fact that xml really sucks badly.

    42. Re:Figures off by a factor of 10 to 100 by tomhudson · · Score: 1

      By the way, in your sample app were you parsing that XML with actual PHP code or the XML functions built into the language or available as modules? If it was the former then your benchmarks are worthless as you clearly don't have a clue about how to use PHP.

      Neither - strictly in c - much quicker. No php code (or any scripting language) is used in the custom server.

    43. Re:Figures off by a factor of 10 to 100 by tolan-b · · Score: 1

      I can have it both ways. I was referring to the examples you gave, all but one of which don't apply in most production environments (which almost exclusively use a bytecode cache). Yes I agree that PHP code runs slower, no it's not because of most of the points you made, and no in most environments the speed the code runs isn't the limiting factor, it's I/O and DB, as several other people have pointed out in this thread.

      We saw an 90% reduction in load between APC disabled and enabled. So yes 10x isn't out of the ballpark you're describing. With a small script you won't see much difference, with larger apps there's a big overhead in re-parsing for every request, even after selective inclusion and caching strategies.

    44. Re:Figures off by a factor of 10 to 100 by tolan-b · · Score: 1

      My point was that you're talking about PHP vs C/C++, and I'm saying that most l33t C/C++ coders use libraries too. As it happens the same libraries that PHP uses.

    45. Re:Figures off by a factor of 10 to 100 by tolan-b · · Score: 1

      I thought you were referring to your PHP vs C benchmarks sorry.

    46. Re:Figures off by a factor of 10 to 100 by tomhudson · · Score: 1

      Hey, it's all good :-)

      I have no real beef against php - I use it myself. My real beef is with people who think that php (or java) is only "a bit" slower than c. Or who think xml is a godsend and every problem that can't be solved by xml can be solved by adding MORE xml (bet you've run into at least one boss who thinks that). Then you get the guy from marketing opening up HIS yap about how "we'll just do it in xml". Like that will solve the problem somehow. Even though he's never seen raw xml in his life - except when he accidently opens it up in his web browser and goes "WTF is wrong here?"

      Like the time the boss asked for a database dump in xml so he could "import it into his spreadsheat." "Look, here's the link, just click on it and it'll generate a .csv file in real time which you can open no problem." "I want it in xml." "Too bad. You're getting it in csv." "Why don't you do what I tell you for once?" "I do, when you tell me to do something that makes sense. This doesn't. Trust me on this, I'm watching your back for you."

    47. Re:Figures off by a factor of 10 to 100 by tomhudson · · Score: 1

      I'm not disagreeing that people use libraries, or even the same libraries. Just that some situations, it doesn't make sense to do like everyone else does. That's why we have a gajillion different programming languages, different hardware, different operating systems ... :-)

    48. Re:Figures off by a factor of 10 to 100 by tolan-b · · Score: 1

      Sure, and they all (even VB.Net!) have their places. PHP happens to work pretty damn well for most web applications, where CPU usage for the app usually isn't that intensive but the ability to rapidly change and develop your functionality is often vital. :)

    49. Re:Figures off by a factor of 10 to 100 by tolan-b · · Score: 1

      Hey now you've stopped wailing on PHP we can be friends ;)

      Completely agree that PHP is slower, of course it is, it's written in C so there's no way it can be faster than C!

      I still think the original point of the article is BS though. If we were talking about some sort of simulation cluster I'd leap to agree, but really most of the time PHP is pretty unlikely to be doing anything very processor intensive. If it is then I'd suggest that in most cases there's a logic problem rather than a language problem.

      Something that may be of interest btw, I wrote a front controller to wrap our CMS in this:

      http://github.com/indeyets/appserver-in-php/

      Which is basically a true FCGI-style app server for PHP (currently it's using SCGI, but same gig and FCGI is on the way. It's all very alpha atm though). So instead of PHP's default FCGI behaviour (maintain the same PHP interpreters but still rebuild the app itself on each request) it behaves as SCGI/FCGI should, the application keeps running and services requests. With 10 worker threads (running on the PHP CLI binary and listening on sockets) the performance of the app more than doubled over mod_php+APC in one go, and that's over APC's already very significant improvement over vanilla PHP. That's with everything cached though, so PHP was doing very little apart from instantiating the app then telling it to do it's stuff, which mostly consisted of fetching the cache, so it's not that surprising that the setup overhead was the majority in this case.

      And yes I agree about XML too, we use XML for object metadata which it's pretty handy for, but cache it into PHP arrays on disk as soon as humanly possible.

    50. Re:Figures off by a factor of 10 to 100 by tomhudson · · Score: 1

      So, are you going to play the current contest?

      You could probably find a php-related domain name that's a zombie. It only took me a minute, using random names and whois from a terminal window, to find out that phprocks.com is currently expired and shows as being in the 30-day redemption period (but even that has passed), and will probably become available over the next week once they update the status. It's also about to pass through pending-delete phase, since it expired Nov 7th, 2009. It qualifies for the contest, since it shows up in the wayback machine.

      Don't bother using a "domain-name-sniping" service ... just wait until it goes back into the pool (it won't show up in a whois search) and grab it. BTW, you'd be at least the 3rd owner, since the current owner sniped it the previous time it expired.

    51. Re:Figures off by a factor of 10 to 100 by Pseudonym · · Score: 1

      I have no problem with reference counting, just reference counted strings. Reference counted strings mandates a performance tradeoff for you, which almost always turns out to be the wrong one in practice. If you need reference counting, you can implement it yourself.

      I don't mind reference counting as a design tool, because it usually buys you most of the benefit of garbage collection with less effort than the other manual alternatives. The benefit is that with more manual resource management, you end up having to structure your program around object lifetimes, which for many structure hacking-type applications, puts a limit on what algorithms you can use.

      You're right about the PHP "almost as fast as C" crowd. For completeness, I should point out that the performance impact of PHP versus C is often not as simple as people think.

      PHP applications which are very thin layers of glue spend an appreciable amount of their time in library code and so are effectively C applications with a scripting layer on top.

      The performance of applications in C often degrade over time as they are maintained, and whether or not it gets fixed is often a management issue.

      But the type of application we're talking about here, where the business logic is complex, could certainly benefit from some compilation. Remember, Facebook even hack their kernels so they can serve a thumbnail image with only two disk seeks instead of three. If you're that concerned about latency, PHP seems like an odd choice for anything time-critical.

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    52. Re:Figures off by a factor of 10 to 100 by tomhudson · · Score: 1

      The performance of applications in C often degrade over time as they are maintained, and whether or not it gets fixed is often a management issue.

      Mod +++++ VERY TRUE

      Worst is when they just want it NOW, and "you can fix it later." We all know tomorrow never comes. Then a year down the road someone else looks at it and goes "what an idiot!"

      That's why I'll stick my email in the @blame section, along with a "This sicks. Email me if you want this done right."

      They don't seem to understand that an extra 15 minutes of "thinking time" before writing a line of code always more than pays for itself.

    53. Re:Figures off by a factor of 10 to 100 by tolan-b · · Score: 1

      "phprocks.com"

      Heheh, I wouldn't go that far, but it's perfectly serviceable ;)

      Like the contest idea but don't really want any new domains just now :)

    54. Re:Figures off by a factor of 10 to 100 by tomhudson · · Score: 1

      You should see my second entry. If you're a "geek" typo-squatter, you'll be going "WTF!?! How did someone let that lapse for almost 5 YEARS????"

  67. so where is the example of a company doing this? by cenc · · Score: 1

    I am curious about an example of a company that has really done this conversion, and what their savings was like. Where is it?

  68. Time for Congress to legislate language efficiency by dirkdodgers · · Score: 3, Funny

    This is brilliant! I think it's clear now the direction we must go. Overuse of energy-guzzling languages like PHP have put us on an unsustainable trajectory fueling out of control global warming.

    Congress must act to regulate the use of these energy-guzzling languages. No longer will programmers and corporations be permitted to turn out inefficient code with impunity.

    PHP, Perl, Ruby, Bash, your days are numbered!

    Just wait until we can get UN involved. Python, you and your CO2 spewing simplicity are next!

  69. An architectural perspective by GeorgeFairbanks · · Score: 1

    First, a few helpful links:

    Amdahl's law says that if Facebook were to switch from PHP to C++, the best possible improvement in the overall processing time is proportional to the total time spent in PHP now. If PHP processing accounts for 90% of the time and they reduce that to zero, they'd have a 10x speedup. However, if it accounts for 10% of the time and they reduce it to zero, they'd have about a 10% speedup.

    So, the question is: How much time (overall) is spent in PHP processing? My guess is not very much. As other posters have pointed out, there are disk accesses and MySQL. And quite a bit is cached in Memcached.

    The original article is slashdotted now, so I'm not sure if it says what those 30k servers are doing, but Facebook has more than just PHP running. Perhaps a thousand of those servers are running Hadoop, probably calculating the social network.

    From an architectural perspective, it probably does not make sense for them to optimize for processing speed (i.e., switch PHP to C++) if their performance is acceptable. That's because they face larger risks: modifiability and time to market pressures. They may worry that switching to a statically typed language (such as C++, but Java would be similar) would make new feature development slower. If they could have both, great, but these two quality attributes often trade off against each other. A design with better performance may hinder modifiability, and vice versa.

    I don't mean to start a language war -- I'm speaking broadly about the idea that dynamically typed languages (PHP, Smalltalk, Ruby, Python, ...) yield programs that are faster to write and modify compared to statically typed languages (C, C++, Java). You may disagree with that generalization, but you may agree that others think it is true, and are therefore acting rationally if they choose a dynamic language when they want modifiability.

    Disclaimers: I knew Aditya in school but haven't spoken to him about Facebook; I am writing a book on software architecture.

  70. Wt is good, but not for this kind of task by Anonymous Coward · · Score: 0

    I'd actually say that Wt can be a more productive framework than resorting to writing individual pages in classic PHP. I'm not sure that I'd use it for general purpose work, however.
    While I agree that C++ is a much better programming language (no implicit declaration, decent type checking, access to good general purpose class libraries, a clear understanding of what is actually happening underneath, and the Standard Template Library - a collection of code that rivals the most beautiful hills of Scotland in implementation).
    However, I'd not want to run native libraries/executables on a production web server. I can only imaging the security nightmare, and the potential for core dumping of web server processes, although with apache, the parent should re-spawn the workers... Also I'd have to write at least some fairly significant classes myself to replace functionality that is standard in the PHP libraries.
    The big issue for any web application that I have ever written, has been performance of the database queries, not the frontend code. If you want to reduce the number of servers, developer effort would be best spent hiring people to look at caching, query optimisation, and load distribution; not re-writing the front end in C++.

  71. One word... by pubwvj · · Score: 1

    Compile.

  72. Can I play? by bieber · · Score: 1

    Why stop at 10? Since we're pulling numbers out of the air anyways, why not take a conservative estimate of 100 for the ratio of PHP to C++ execution, so they could run the whole thing on just 250 servers!

  73. Environmental concern or personal agenda? by Anonymous Coward · · Score: 0

    This seems to me like the poster has an axe to grind against PHP in general.

    Even if you accept the "conservative" estimate of C++ being 10 times as efficient as PHP, you are still blindly assuming that each of their 30k servers is CPU bound. I find it just as plausible that memory, bandwidth, and/or storage are the limiting factors.

    Don't let a lack of facts stop you from using the "environment" to drive your agenda though, it doesn't seem to stop anyone else.

  74. Wasted Energy by ChaoticCoyote · · Score: 2, Insightful

    Isn't this "study" a waste of energy?

    I am a C/C++ programmer by trade; I'm not fond of PHP. Yet this "C++ saves energy over PHP" argument smells like more selfish politics to me. And selfish politics is what is bringing doom down on humanity's head -- the use of PHP vs. C++ is a sideline, a distraction, and only truly valuable for people who have a philosophical axe to grind.

    You want to save a lot of energy? Shut down all the computers running MMOs. And stop wasting cycles looking for alien signals in cosmic radio waves. And get rid of banal YouTube videos... and... the list is endless. The science behind Global Warming is being used to further political and social agendas that have little or nothing to do with adapting our species from a potential environment change.

    In the end, selfish politics will kill us all. We will become a footnote in history is we do not discover enlightened self-interest.

  75. 10 to 1 is nonsense by Anonymous Coward · · Score: 0

    10 to 1? Nonsense!! If they had used C++, they'd be no Facebook ... yet, for zero carbon footprint. Extremely efficient.

  76. Green Languages?? by nurb432 · · Score: 2, Insightful

    Ok, this has gone WAY too far .. we all need to just take a step back..

    --
    ---- Booth was a patriot ----
  77. If you believe this, invest in Iceland banks by Antique+Geekmeister · · Score: 1

    That's right, because a similar level of chicanery is going on in this claim. A small factor of system expense is being extended into a region of pure nonsense. There are plenty of more reasons to have a large, scattered base of servers. These include:

    * Local database mirroring and caching to improve response times for dynamic content.
    * Local proxying of static material to improve response times and to improve upstream bandwidth costs, and reduce the number of connections made to the core servers and avoid DDOS'ng yourself.
    * The idea that PHP's function calls to pull and present disk-based or data-based material would somehow magically reduce the overall cost and need for servers, even theough the request for material is probably one of the most efficient steps.

    I've had eager young engineers extrapolate their favorite tool into being the great solution to all issues this way before. Educating them in the concept of looking for the _other_ bottlenecks is a painful process, and I wish I could have found a good course in it before a lot of recent projects myself.

  78. CPU is only one factor by stardragon · · Score: 0

    Few web applications are CPU bound. Most are bound by I/O, often that is between the data store and the app. No language selection is going to resolve that problem. If you're really concerned about the carbon footprint of your app, you're better off spending you time refactoring to optimize its performance rather than rewriting your {PHP | Ruby | Python | Perl} code in C++ or C.

    Also consider the fact that many web applications are over-deployed. An idle server consumes as much energy as a busy one. You could save yourself a lot of carbon by using performance monitoring tools to determine the optimal number of servers to run your app.

    1. Re:CPU is only one factor by ls671 · · Score: 1

      Very good point, no-brainer optimization is often the best bang for the buck you can get without regards for the language used !

      On a funny note, something triggered when I read:

      > You could save yourself a lot of carbon

      Now I know what it is: I think that nobody should try to save carbon, this would imply that one needs to produce more in the first place in order to save it ;-)

      Again, not that I am trying to be the grammar police or anything (I hate that), but I swear something really bugged me we I read your sentence.

      --
      Everything I write is lies, read between the lines.
  79. C++ is bad for the environment by pydev · · Score: 1

    C/C++ is mabye 10-100x faster and more efficient for carefully written inner loops. At the level of whole systems, it's an entirely different story. Because C++ lacks garbage collection, people end up retaining far more memory than they need to. Because algorithms are far harder to express in C++, people end up using brute force algorithms (linear search, etc.) a lot. Because templates need specially compiled versions for each combination of template arguments, you end up with dozens of different instances of basically the same code.

    For web applications, there's probably not much of a difference either way; but in scripting languages like PHP, all the inner loops that are needed are already written in C. For scientific computing, C++ is acceptable because a lot of applications really are mainly about the inner loops.

    But for many applications, like GUIs, C++ not only fails to be faster, it also ends up making everything a lot slower and more bloated. If our desktops were largely written in Python, Ruby, or Smalltalk, we'd be using a lot less energy and be able to get by with smaller, less-powerful machines. That's in addition to all the savings from the reduced number of bugs and reduced development costs.

    1. Re:C++ is bad for the environment by cpghost · · Score: 1

      Because C++ lacks garbage collection, people end up retaining far more memory than they need to.

      Not so with smart pointers: they are part of TR1 already.

      Because algorithms are far harder to express in C++, people end up using brute force algorithms (linear search, etc.) a lot.

      STL provides excellent containers, and with TR1/Boost, you have hashed containers, regexp etc...

      Because templates need specially compiled versions for each combination of template arguments, you end up with dozens of different instances of basically the same code.

      You don't need to over-templify your code. In fact, for web apps, you'd be using POCO or similar libraries that are rather light on templates (though they use them too, of course). IMHO, many C++ developers write bad code, because they don't use current techniques and libraries. That's the problem with C++ development. C++ used properly can be extremely efficient.

      --
      cpghost at Cordula's Web.
    2. Re:C++ is bad for the environment by luzr · · Score: 1

      C/C++ is mabye 10-100x faster and more efficient for carefully written inner loops. At the level of whole systems, it's an entirely different story. Because C++ lacks garbage collection, people end up retaining far more memory than they need to.

      Only people still using manual memory management.

      Because algorithms are far harder to express in C++, people end up using brute force algorithms (linear search, etc.) a lot.

      Is this some kind of joke? I would swap C++ for PHP anytime to actually GAIN possibility to express algorithms easily.

      There is no such language where experienced programmer could do refined algorithm a well as in C++.

      Because templates need specially compiled versions for each combination of template arguments, you end up with dozens of different instances of basically the same code.

      Yeah, app code might occupy a little bit more. Really big apps in C++ have say 20 MB compiled. So they would be only 15MB without extensive template use. Hardly any difference if your memory space is in gigabytes.

      But for many applications, like GUIs, C++ not only fails to be faster, it also ends up making everything a lot slower and more bloated.

      It is hard to make general statements about C++ and GUI. In some cases, like MFC, you are certainly true. Other like Qt are better. Some claim to outrun everything else in terms of both development costs and runtime performance:

      http://www.ultimatepp.org/www$uppweb$vsswing$en-us.html

      If our desktops were largely written in Python, Ruby, or Smalltalk, we'd be using a lot less energy and be able to get by with smaller, less-powerful machines. That's in addition to all the savings from the reduced number of bugs and reduced development costs.

      What a pity they are mainly written in C (GTK, Windows), Java (Android) and Objective C (MacOS X) then...

    3. Re:C++ is bad for the environment by pydev · · Score: 1

      IMHO, many C++ developers write bad code, because they don't use current techniques and libraries. That's the problem with C++ development

      The problem with C++ development is that the language has become so enormously complex that nobody can write correct code in it. And what you call "current techniques and libraries" is a ridiculous set of workarounds for fundamental language design problems.

      I've been using C++ as my primary development language for more than 20 years. It started out as a fairly reasonable set of C extensions, but it has turned into a complete and utter disaster.

      I'm not going to start another open source project in C++, and I'm not going to accept any contracts for C++ development anymore either. C++ needs to die, and the sooner the better.

  80. Unfair Comparison by Anonymous Coward · · Score: 0

    I think this is also an unfair comparison. what are you considering a PHP page. A page mostly of HTML and a few PHP tags? C++ has to render all of the HTML so how would you compare that? I have worked on programs that where 100% coded in PHP, and HTML was created by either echo or print statements, these are nightmares to maintain.

  81. Re:it's stoopid because by Anonymous Coward · · Score: 0

    climate change is only bad for the poor living in coastal corrupt hell hole
    here in canada, and in northern usa it is a good thing since our agricultural output will be higher

  82. Middle ground by CustomDesigned · · Score: 1

    The script languages like Perl/PHP/Python/Ruby are dynamic, and fill a role that C++ can never fill. Further, while GC can be added to C++, it changes the programming style so much that it is nearly another language (makes using 3rd party libraries tricky).

    Java is a middle ground between C++ and script languages. It has the garbage collection, dynamic class loading, "safe" execution model and extensive libraries like PHP/Python/Ruby, but long running programs like web apps get compiled to optimized native code as they run. Yeah, the language has warts, but it is still more productive vs programmer time than C++.

  83. The dog ate my computer by wytcld · · Score: 1

    This is as stupid as the "news" a month back claiming a pet dog used the same environmental resources as a large SUV. The problem was, multiplying the claims for agricultural land used to feed one dog by the number of dogs gave as a result that 10% of our agriculture is feeding dogs. Why is that obviously wrong? Because the whole pet food industry accounts for less that 1/10 of 1% of the value of agricultural production.

    We're going to see more and more of this shit. Everyone will be competing to get their 15 minutes of fame by claiming that X - something that annoys them, like PHP or, evidently, dogs - is the major overlooked factor in destroying the Earth's climate. Because they know our press is so stupid in basic scientific literacy that they'll jump at the chance to put a headline over the claim, since we're all bound to read it just in case there's a there there.

    --
    "with their freedom lost all virtue lose" - Milton
  84. Compiled PHP vs interpreted PHP by Anonymous Coward · · Score: 0

    If Kensai7 is so concerned with the environmental impact of (supposedly slow) interpreted PHP, then (s)he should write an efficient PHP compiler.

    This would not only make the Facebook site more environment friendly, but other PHP powered sites as well.

  85. APC is heavily used by FB by Anonymous Coward · · Score: 0
    Indeed a ton of the APC features are built by the facebook folks.

    Here's one of their 2008 presentations on the topic - apc @ facebook.

  86. Plus mountain dew and doritos by sam_handelman · · Score: 2, Insightful

    Computer programmers are people with their own carbon footprints, $FLATULENCE_JOKE. So, people have raised objections to the underlying efficiency argument, I tend to agree with the people who estimate that the energy savings would be less than 10-fold, but it's not like I've looked at the diagnostic output of their servers.

      Labor costs money, right? So if you assume that $X million worth of servers and electricity are cheaper than $X million worth of programmer time to reimplement the whole mess in C, then it's probably minimizing the carbon footprint to leave it alone. This ought to be a very simple business decision.

      There are certainly cases where this is not true, but for most purposes, dollars spent on computer programming go directly to carbon footprint. I'm a Socialist, certainly not a free market fanatic by any stretch, but when it comes to spending millions on highly specialized, skilled labor to reduce carbon footprint, I doubt that it's worth it unless the electricity you save costs more than the specialized labor.

    --
    The good and new comes from no quarter where it is looked for, and is always something different from what is expected.
  87. Yes by Anonymous Coward · · Score: 0

    I was hired to do C++ code on a mature project. The original coders were quite skilled. The code was well commented, and the conventions used were (fairly) consistent. The code itself was well-spaced and readable with descriptive variable names.

    Personally, I think C++'s greatest failing is that it is too hard for most developers to do it well. The greater difficulty is a consequence of its greater power; it gives developers a wider variety of options for performance optimization. But it is hard.

    Many software developers have pride issues. They get really intimidated when they must work with someone who is authentically better than they are. So they really, really don't like to admit that doing C++ properly is too hard for them. Instead they will try to say that the language is flawed, and that other languages (which are less powerful and therefore easier to use) are actually, objectively, superior, and that using C++ is pretty much the wrong decision in any case. Needless to say, I disagree.

  88. Plus, C++ is an environment-hostile choice by Jesus_666 · · Score: 3, Funny

    C++ is much too slow and carries too much of an overhead. And it usually requires an operating system on a general-purpose processor. You could go to hand-optimized binary code written directly for the processor but that still leaves us with inefficiencies.

    Imagine if every website was implemented as an ASIC. Then we could talk about efficient datacenters. Maybe, if you're relly strapped for cash, you could implement each website in an FPGA. But that should only be a stopgap measure until you can afford a proper implementation.

    --
    USE HOT GRITS WITH STATUE OF NATALIE PORTMAN (NAKED AND PETRIFIED)
    1. Re:Plus, C++ is an environment-hostile choice by Nazlfrag · · Score: 1

      And remember that doing anything other than this makes you an environmental terrorist directly responsible for destroying the entire planet. You monster.

  89. Without merit by Anonymous Coward · · Score: 0

    Its all data. The PHP code that mashes it together is a tiny fraction of the backend processing which manages the data store.

  90. PHP harder to test than C++ by butlerm · · Score: 1

    In general code written in a dynamically typed language like PHP is harder to test than code written in a statically typed language like C++. The reason why is that statically typed language compilers catch hundreds of problems at compile time that dynamic languages typically cannot catch until run time, and with complete code coverage at that. Misspelled variables and other minor typos anyone?

    In a sufficiently large project, all the time one might save not going through an extended compile cycle quickly gets eaten up by the extra testing overhead, testing which for user interface intensive applications is rather difficult to automate.

    Of course the developers have to know what they are doing. If you run into more than one dangling point or array overflow problem per ten thousand lines of code, someone is either ignorant or careless. C++ programming is not for code monkeys.

    1. Re:PHP harder to test than C++ by porneL · · Score: 1

      This is not a problem in PHP.

      If you have editor with auto-completion, misspellings are uncommon. Other kinds of errors are caught (and logged) as soon as faulty code is executed. With short edit-run cycle it's pretty quick.

      It's not perfect, but OTOH C++ compiler won't tell you about all memory leaks, dangling pointers and buffer overflows at compile time.

      C++ has runtime errors too, and you won't easily get logs with line numbers where your memory corruption happened.

    2. Re:PHP harder to test than C++ by butlerm · · Score: 1

      1. If you are getting more than one memory corruption problem per programmer year in C++, something is seriously wrong with the competence of your developers.

      2. The edit test cycle is fine the first time you develop a page or whatever. Then you need to make a change to an internal interface used by thousands of pages. Testing all of them is not fun. A statically typed interface can be checked by a compiler in a fraction of the time.

    3. Re:PHP harder to test than C++ by porneL · · Score: 2, Insightful

      Developers that are diligent enough to make only 1 memory-related bug/year can certainly spell variable names correctly.

      If you have statically typed language, you rely on types. If you have dynamic, you rely on unit tests. Both are probably equally slow :)

    4. Re:PHP harder to test than C++ by butlerm · · Score: 1

      Developers that are diligent enough to make only 1 memory-related bug/year can certainly spell variable names correctly

      If they are stuck using a language that doesn't check anything until runtime, sure.

      If you have dynamic, you rely on unit tests

      But how exactly do you go about doing unit tests of the front end of a web application? The short answer is, you can't, not without unusually sophisticated tools. This is a serious problem even if you write the web application in C++, due to all the javascript stuff that lives on the browser these days.

      There are a lot of things than *can* be checked ahead of time with a dynamic language, it is just that no one does, because the languages do not require that it be done. That is something that ought to be fixed. Surely someone out there has written a static analysis tool for Python or PHP that finds a large class of programming errors prior to runtime. Or even better, a static analysis tool that analyzes a dynamic language web app, client side javascript, an SQL database and the interactions between them? Anyone?

    5. Re:PHP harder to test than C++ by Waffle+Iron · · Score: 1

      The reason why is that statically typed language compilers catch hundreds of problems at compile time that dynamic languages typically cannot catch until run time

      That's the good news. The bad news is that the vast majority of those "problems" are issues created by the static type system itself.

    6. Re:PHP harder to test than C++ by porneL · · Score: 1

      > But how exactly do you go about doing unit tests of the front end of a web application?

      Unit testing in PHP isn't different than in other languages. You split code into testable chunks and hammer them with PHPUnit.

      > due to all the javascript stuff that lives on the browser these days.

      How is that related to C++/PHP? And would you just run Facebook without unit tests? (good luck!)

      Anyway, for JS there's Selenium and it can integrate with PHPUnit. UI testing is difficult, and browser-hosted tests are especially fragile and finicky, but that's not PHP's fault and C++ won't fix it.

    7. Re:PHP harder to test than C++ by butlerm · · Score: 1

      If a type system creates more problems than it is worth, you can certainly use a crash and burn development methodology with a dynamically typed language. Mostly though, the trend in dynamic languages is to add type annotations, not take them away.

      Sufficiently large systems (Google: "programming in the large") are rarely developed in unannotated dynamic languages because they are simply too fragile - too many errors cannot be caught before deployment. If it was a net loss, nobody would write programs in statically typed languages, ever.

    8. Re:PHP harder to test than C++ by Nicolay77 · · Score: 1

      I can't say I do agree with you, but I don't disagree either. I think that this is one of the premises that only time can tell.

      There's a C++ Web framework to test your premise with a high profile web project:

      http://www.webtoolkit.eu/wt

      I really hope somebody uses it for something facebook-big and we hear about it.

      --
      We are Turing O-Machines. The Oracle is out there.
    9. Re:PHP harder to test than C++ by Nicolay77 · · Score: 1

      I have just seen that the article was written by the guys who wrote this toolkit.

      So feel free to mod my other post as redundant.

      I need to at least RTFS.

      --
      We are Turing O-Machines. The Oracle is out there.
    10. Re:PHP harder to test than C++ by butlerm · · Score: 1

      I am not saying that everyone should go out and write large web applications in C++. I am saying rather that dynamic languages have serious problems that need to be addressed before they become ideal for such development. The best way I know to to address it is with static analysis tools, which seem to be hard to come by for dynamic languages.

  91. C is faster than PHP by Anonymous Coward · · Score: 0

    C is certainly faster than PHP (I have written programs in both), but I don't think it is too great of problem in this way. If you want to make your PHP code take up less energy then possibly you can run an optimizer on it and store the optimiezd code. This would speed it up a bit (although it doesn't seem to help much).

    I have written two programs, an assembler in C, and a program to copy the assembler's output to the hard drive image using PHP. The C program runs nearly instantly, while the PHP program, even though it is much simpler and just calls a C function to do the direct copy anyways, takes 1 second to run.

    And, of course, like mentioned, you do need water and heat and stuff to live, and the major cause of global warming is the sun. And global warming is not as serious as many people says, but nevertheless, if you want to help by being more environmentally friendly you can please do so (as long as it is not a mistake).

  92. They would need zero servers if they used C++ by lma · · Score: 1

    That's because if they were writing in C++ they would still be writing the application and wouldn't have any users yet. Larry

    1. Re:They would need zero servers if they used C++ by maxwell+demon · · Score: 1

      Compile servers are servers, too.

      --
      The Tao of math: The numbers you can count are not the real numbers.
  93. This is what COP15 should have... by heidaro · · Score: 1

    ...covered. Ban all programming languages except assembler! They emit CO2 and will lead to the destruction of the universe!

  94. optimizing php by itzdandy · · Score: 1

    I do some basic php development and really couldnt imagine having to do the same work in C++. It would take so much more time it would make it nearly impossible to do.

    so maybe its time to optimize php? Perhaps do some hardware acceleration of php code with CUDA -or- maybe if just focus on the php interpreter and make it more efficient.

    as with any scripting language, an un-optimized interpreter will run the script code an order of magnitude slower or worse than a pre-compiled program.

    I have seen some comments that it isnt likely to cause such a different in server needs because it doesnt take into account I/O performance. Well consider that everything must be bought with some sort of budget in mind then consider that a nice dual-quad core server will cost many thousands of dollars more than a single core2duo server. a 2 socket 3ghz quad core with 24Ghz aggregate x the 10:1 ration means you need a single 2.4 cpu so a core2duo e8400 is actually worth twice the cpu power for pre-compiled code vs a dual quad core system running php. The different is price could be spent on SSD disks or a faster SAS array and actually improve performance.

    you can test this yourself by running a bash script to run 10,000 queries on a mysql database with the compiled mysql tools vs a php script to do the same thing (run on the command line) and then subtract the time the database took to return the data. This is a very typical workload for php and it will lose this race everytime.

    do I need to put some result here? no, do it yourself so you can see first hand.

    1. Re:optimizing php by BlortHorc · · Score: 1

      One of the cool things about PHP5 is that you can take objects that are used all the damn time, and implement them in a more efficient language, yet still access them from PHP as if they were native objects. This, one assumes, is the basis for TFA's rant, but you only really see the benefits of such implementations if they are classes you use _all_ the fucking time, if it is something you see once in a blue moon the performance benefit will be unmeasurable, as opposed to the dev time which will of course be far higher for C++. We didn't all get woodies for RAD tools for no damn good reason, of course things are quicker to develop in PHP.

      Someone repeatedly drown and resuscitate this damn editor until it no longer works, because really, no fucking clue.

  95. Mod SoulSkill as both -1 Troll and -1 Flamebait by FlyingGuy · · Score: 0, Flamebait

    Seriously, why was this even posted. While we are at it, lets Mod SoulSkill as +1 Revenue Generator so even then this should get scored as -1 "What! Are you fucking kidding me!" ( with apologies to Robbin Williams )

    But on a more on-topic note, PHP and C++ are languages for two totally different things and if SoulSkill doesn't know that, he has no business being a "editor".

    --
    Hey KID! Yeah you, get the fuck off my lawn!
  96. Re: FORTRAN by butlerm · · Score: 1

    FORTRAN is designed to do numeric processing. FORTRAN compilers are very good at optimizing such code. FORTRAN is not at all optimal for doing much of anything else.

    Similarly, with the right framework, someone might write a general purpose web application in C++, because you can make string processing code a relatively painless exercise with the right class libraries. Plain old C, on the other hand, is much worse - essentially a language designed not to do string handling very well or very reliably.

    Even with C++, there is an enormous interoperability and efficiency problem with strings of different flavors, and I would put rank that problem as #1 on a list of why few people do general purpose business programming in C++. I have *never* seen a standard C++ library compatible C++ string implementation that was worth using in both compile time and run time efficiency terms. Certainly the implementation that comes with GCC doesn't qualify...

  97. I call shenanigans by BlortHorc · · Score: 1

    This guys takes some benchmarks that have absolutely no basis in actual real world performance and beats his drum.

    What, does he want a medal for a beat up on /.?

    Drop this fool down a well, and leave optimisation to those who understand it.

  98. True History by Nomen+Publicus · · Score: 1

    1. Prototype PHP code written and tested in an afternoon.
    2. Business case written in an afternoon (forgetting to include the profit generating point.)
    3. Vulture Capitalist drinks too much at lunchtime pitch and agrees to provide $BIGNUM
    4. Development of real codebase begins.
    5. Vulture Capitalist sobers up and demands that the new service starts NOW!
    6. Prototype code goes into production.
    7. Real codebase development abandoned.

  99. Process overhead? by slimjim8094 · · Score: 1

    The PHP interpreter can and should run in-process to the webserver. Compiled C++, not so much.

    Now, I imagine Facebook's scripts are really quite simple - fetch from the database and do some formatting. Moreover, they're called like a thousand times a second. Grabbing from the DB is already the expensive bit; C++ won't help that. But starting thousands of processes a second can't possibly be faster than the in-server interpreter effectively just looping.

    Am I missing something or is this a pointlessly stupid article, bordering on troll?

    --
    I have developed a truly marvelous proof of this comment, which this signature is too narrow to contain.
    1. Re:Process overhead? by BitZtream · · Score: 1

      Why exactly would you not run your C code in process? Just to give PHP a chance at an advantage or something?

      --
      Persistent Volume manager for Kubernetes - https://github.com/dwimsey/openshift-pvmanager
  100. Re:so where is the example of a company doing this by Cassini2 · · Score: 3, Interesting

    I have done projects like this, and received massive speedups and performance increases. The issue is that you need to understand the real reasons why rewriting a program in C and/or assembly gives a massive performance increase. Inevitably, the reason why the C program is so much faster, is that a programmer has went through and rethought the application. The programmer eliminated string copies, string manipulations, data communication overheads, and data manipulation/translation overheads by rethinking the programs design.

    For example, imagine a very simple application designed to take a digital input, and display a red/green indicator to a user depending on the input state. Count every time a major string overhead, data communication overhead, or data translation overhead occurs in each of the proposed solutions.

    Web Solution
    1. Input digital input via PLC (Data Overhead #1)
    2. Upload data from input via PLC communications protocol to PC (Data Overhead #2)
    3. Make data available to other programs, for example RSSQL makes real-time I/O appear as SQL database queries (Data Overhead #3)
    4. Use PHP or ASP to generate a web page based on a SQL query for the real-time input (Data Overhead #4)
    5. Use a web browser to query the relevant web page. (Data Overhead #5)
    Web Solution performance: it might be able to update the display screen every 1/5 second.

    Embedded C Solution
    1. Input a data point using real-time I/O
    2. Paint a computers display screen accordingly. (Data Overhead #1)
    C Solution Performance: 1/60 second, limited by the refresh rate of the monitor.

    Assembly / Microcontroller Solution
    1. Input the data point, with INP , AX
    2. Output the data point to a Red/Green LED, with OUT AX,
    Note: the assembly implementation doesn't have any string manipulation, so it doesn't have any significant data overhead.
    Assembly Execution Time: Less than 1 micro-second.

    The crucial concept from the above example is that the programmer reduced overhead and execution time, by simplifying program operation. The problem was solved in 3 different ways, and the fastest solution wiped out all the communication/string/data management overhead. If you want to make a computer program very fast, it is necessary to reduce data communication, string manipulation, and complex data structure overhead.

    Which languages do this and why:
    Level 1 - Simplest: Assembly is the best at wiping out string overhead, because engineers willingly migrate complex functionality to hardware before implementing it in assembly. In this case, the display screen was eliminated in favour of a direct output to an LED.
    Level 2 - Low-Level: C is remarkably quick at string manipulation programs, because programmers minimize the amount of string manipulation. String manipulation in C sucks, and is difficult to get correct. As such, programmers attempt to minimize it, or use optimized tools like lex/flex or yacc/bison that automate the difficult problems.
    Level 3 - Garbage Collected: Java and .NET encourage carefree string use and data structure use. The have automatic garbage collection. As such, minimal penalties exist for the programmer to use strings.
    Level 4 - Scripted: PHP, Perl, Python are higher level languages focused on easy programming for high-level tasks. They pretty much assume the programmer doesn't care about the overhead of processing strings or complex data structures. Instead, they make it easy for the programmer to program the complex data structures.

    An application like FaceBook has to have some complex data structures to do its job. In that case, a migration from PHP to C will likely not produce great benefits, because the C program still has to do all the same work the PHP program does. The old rule was that interpreters were very slow. With modern techniques, just about any language can be sufficiently compiled to

  101. Re:Time for Congress to legislate language efficie by BlortHorc · · Score: 1

    Dude, are they going to take in to account the extra time your computer needs to be on to implement all that shit long hand? No? So you're saying your suggestion is something of a funny that failed or a troll that needs some souping up?

    Or is there a joke in there that you are crap at telling?

    Inquiring minds want to know.

  102. So the bindings make a difference? by SanityInAnarchy · · Score: 2, Insightful

    Why is it that a decent PHP (or Python, or Ruby) MySQL binding couldn't do the exact same thing?

    --
    Don't thank God, thank a doctor!
    1. Re:So the bindings make a difference? by tomhudson · · Score: 1

      You're still initializing your interpreter for EACH result set. Once you add an interpreter to the equation, you've already lost the race. With c, you only need a struct with pointers to the variables you actually use - a lot more compact - and since the actual values are not copied into the interpreter and then copied back out of it, then back into it again, then flushed, you save a lot of time AND memory.

      Plus, php deliberately doesn't let you execute multiple statements with one call - anything after the first semicolon is stripped from your query as a "security measure". Same with php and postgresql.

      This is to help prevent sql injection attacks. For example, someone can't put their user name as "joe blow';drop table users';select 'hacked" (notice the embedded single quote before the semicolon) so that "select pw_hash from users where user_name='$username'" doesn't become "select pw_hash from users where user_name='joe blow';drop table users;'select 'hacked';"

      Of course a c program has to do sanity checks on data as well, but it's a lot easier. For example, if you KNOW that you'll never get a response from the end user that's longer than 2k, as soon as you exceed that limit, stop reading from the socket, send a server redirect to goatse.fr, and close the socket. This way, you don't end up with someone doing a DoS on you with multiple loooooooooonnnnngggggggggggggg requests. You can also set it so that if the bytes don't show up within n time, close the socket anyway - so no tarpits.

      Hope this helps :-)

    2. Re:So the bindings make a difference? by Annymouse+Cowherd · · Score: 1

      The problem there is that you're using CGI (which runs a new instance of PHP for each request) rather than FastCGI (which keeps a pool of processes active).

      Also you're comparing Apache to a custom written, purpose-built web server. You could probably write said web server in PHP and it would be faster than the Apache/PHP combo.

    3. Re:So the bindings make a difference? by SanityInAnarchy · · Score: 1

      You're still initializing your interpreter for EACH result set.

      What do you mean by "initializing an interpreter"? It's already running, doesn't initialize even with each page in a well-designed system.

      Plus, php deliberately doesn't let you execute multiple statements with one call

      I'm not defending PHP specifically here, because that kind of stupidity doesn't seem like it's implied by an interpreter. Again, you are talking about a limitation in the current MySQL bindings, not in the language itself, and certainly not in the general design of an interpreted language.

      Of course a c program has to do sanity checks on data as well, but it's a lot easier.

      I dispute that. For example:

      For example, if you KNOW that you'll never get a response from the end user that's longer than 2k, as soon as you exceed that limit, stop reading from the socket,

      And if you forget to do that, but you've only allocated the 2k, that's a buffer overflow -- a kind of security vulnerability which you cannot create in PHP. I'd rather have a DoS than a real security flaw any day.

      --
      Don't thank God, thank a doctor!
    4. Re:So the bindings make a difference? by ls671 · · Score: 1

      Bah, just use something like Struts and hibernate, problem solved.

      --
      Everything I write is lies, read between the lines.
    5. Re:So the bindings make a difference? by nacturation · · Score: 1

      Plus, php deliberately doesn't let you execute multiple statements with one call - anything after the first semicolon is stripped from your query as a "security measure". Same with php and postgresql.

      Of course, if you're really into optimizing your code, you'd be using precompiled stored procedures and passing in parameters and not executing raw SQL, which suffers from the "must be interpreted" problems you ascribe to PHP.

      --
      Want to improve your Karma? Instead of "Post Anonymously", try the "Post Humously" option.
    6. Re:So the bindings make a difference? by tomhudson · · Score: 1

      Actually no. PHP is, like all interpreted languages, slower. Also, it doesn't matter if you keep a pool of processes active - a fastcgi script is still running as an interpreter, so it's always going to be slower than a chunk of c code loaded directly into the server.

      Also you're comparing Apache to a custom written, purpose-built web server. You could probably write said web server in PHP and it would be faster than the Apache/PHP combo.

      You might want to rithink that. Why would anyone want to write a web server in a slow interpreter like PHP when they can get the performance benefits and flexibility of c?

    7. Re:So the bindings make a difference? by tomhudson · · Score: 1

      You're still initializing your interpreter for EACH result set.

      What do you mean by "initializing an interpreter"? It's already running, doesn't initialize even with each page in a well-designed system.

      The hell you don't. You have to re-initialize all the variable store. You can't leave around values and variables left by the previous invocation.

      Plus, php deliberately doesn't let you execute multiple statements with one call

      I'm not defending PHP specifically here, because that kind of stupidity doesn't seem like it's implied by an interpreter. Again, you are talking about a limitation in the current MySQL bindings, not in the language itself, and certainly not in the general design of an interpreted language.

      It IS deliberate. It's to help prevent sql injections.

      For example, if you KNOW that you'll never get a response from the end user that's longer than 2k, as soon as you exceed that limit, stop reading from the socket,

      And if you forget to do that, but you've only allocated the 2k, that's a buffer overflow -- a kind of security vulnerability which you cannot create in PHP. I'd rather have a DoS than a real security flaw any day.

      Simple rule: learn how to count. If you can't keep track of your buffer stores, you shouldn't be writing any code that uses malloc. Which means you shouldn't be writing in c.

      Then test it to make sure you didn't screw up. Always use the same entry point for code that manipulates the buffers, so that you NEVER "forget" to do sanity checks.

      If you can't do this consistently, c simply isn't a language for you to use. It's not that hard. The reason programs contain lots of buffer overflows is because people are either lazy, under time pressure to cut corners or "just fix it | ad a feature to it", or simply can't do zero-based math (which is why so many overflows are 1-byte errors).

      And you're wrong about PHP being free of buffer overruns - seek and ye shall find.

    8. Re:So the bindings make a difference? by tomhudson · · Score: 1
      If you're using php, you're still going to be much slower than using the c api and multi-statements. Your queries don't have to be all related to one request - you can process 100 different requests for 100 different users requesting 500 different data sets, as ONE multi-statement. It's not just fast - it's like greased lightning in comparison to php, but it's fastest when you go to the trouble of serving diverse requests. If you use multi-statements one per page request (say for example to get the user info, name, their bio, whatever, as 4 queries) you're missing out on the real power. Set a 2 meg input buffer for the server, concatenate 1,000 different queries, and spool out the response.

      The query optimizer will try to fix things so that there's the least disk thrashing possible, no duplicate reads, etc. It's not the easiest thing in the world, but when it works, you'll just be amazed at how fast things can be.

      It's like the time I got a bit curious as to what the ultimate performance of my hard disk was. I wrote a routine in assembler, and it actually was able to read twice as much data a second as with c - which was only able to hit the disks' official limit. So even c has room for improvement, but the performance gains aren't nearly as much as the switch from, say, php to c.

      Besides, we need more holy brace wars :-)

    9. Re:So the bindings make a difference? by nacturation · · Score: 1

      How would you do this in a web environment? Each request comes in independently so how do you deal with all these different instances of queries needing to be serviced? And if you are waiting until you have 1000 different queries, you're going to introduce delays as request #1 has to wait for request #1000 and unless you have a fairly constant, high volume of traffic, you're not going to be able to anticipate the volume of queries. I suppose you could execute the batch every 500ms or 1000 queries, whichever comes first, though that doesn't guarantee the snappiest response for the user.

      At any rate, now you have me curious... one of these days I'll have to try batching up queries vs. batching up stored procedures vs. executing independently and letting the server figure it out, then compare the relative performance of each.

      --
      Want to improve your Karma? Instead of "Post Anonymously", try the "Post Humously" option.
    10. Re:So the bindings make a difference? by adamchou · · Score: 1

      Plus, php deliberately doesn't let you execute multiple statements with one call

      I beg to differ...

    11. Re:So the bindings make a difference? by snemarch · · Score: 1

      Heh, getting higher disk transfer rate by writing a routine in assembly than C? Bullshit. Unless of course you've done a really silly apples-and-oranges "benchmark" like comparing 1-char-at-a-time FILE* reads to raw buffer-at-a-time read syscalls...

      If you can go faster by doing syscalls in assembly than using posix read(), your libc implementation sucks - it's not asm being faster than C in this case...

      ps: an assembler is the tool that assembles assembly code.

      --
      Coffee-driven development.
    12. Re:So the bindings make a difference? by Anonymous Coward · · Score: 0

      The hell you don't. You have to re-initialize all the variable store. You can't leave around values and variables left by the previous invocation.

      In PHP, maybe.

      In more intelligent languages, not so much. Half the point of mod_perl is that you don't have to do that. I work in Ruby, but I think the mod_perl example proves my point, especially since it's older than anything I do.

      Values and variables from the previous invocation are no more relevant to clean up than values and variables from the previous invocation of a given method -- in a language that actually supports properly scoped variables, just let them fall out of scope and be garbage-collected.

      certainly not in the general design of an interpreted language.

      It IS deliberate. It's to help prevent sql injections.

      I realize that -- though many discussions on the page you linked to seem to be showing ways it's possible anyway.

      My point was, specifically, that nothing about the design of PHP, nor anything about the mere fact that it's a scripting language, prevents the development of better bindings.

      Basically, your argument here is an argument about specific bindings and libraries -- in which case, I could turn it around and say that C sucks because it doesn't have a good web framework.

      Simple rule: learn how to count.

      That would matter if I was, oh, combining strings directly. It has nothing to do with this example.

      But let's run with it for a second. In PHP, I don't even have to count this part. In places where I do miscount, the interpreter will probably yell at me.

      In C, if I miscount, bang, security vulnerability.

      I'm amazed you don't see this as a fundamental flaw in the language. This computer on my desk is descended from calculators, and can perform billions of calculations per second. It can count for me.

      If you can't keep track of your buffer stores, you shouldn't be writing any code that uses malloc. Which means you shouldn't be writing in c.

      This one might be valid, but as you've pointed out here:

      Always use the same entry point for code that manipulates the buffers, so that you NEVER "forget" to do sanity checks.

      Compare this to, say, designing the language such that this is not possible to do.

      Maybe we should go with something we can actually agree on: Placeholder values in SQL strings. See, if I always write SQL like this (pseudocode):

      run_some_query('select * from users where name=?', name);

      In that case, the string itself is immutable, and I'm counting on the SQL bindings and/or server to combine it with the value I've passed in a way that makes sense. I don't have to do any quoting, escaping, anything. I can doubly-verify that I have this correct by using a language with different notation for static string literals vs interpolated strings -- in Ruby and Perl, at least, the single quotes above mean that string won't be interpolated.

      Contrast to something like this:

      run_some_query("select * from users where name = '$name'");

      Now I've got a classic SQL injection vulnerability. I have to remember, each time, to escape that value.

      This is one of a set of vulnerabilities that disappear with best practices. There are others which disappear by not using C.

      The reason programs contain lots of buffer overflows is because people are either lazy, under time pressure to cut corners or "just fix it | ad a feature to it",

      The reality is that it will always be this way.

      But more than that, the reality you don't seem to be accepting is that everyone makes mistakes. Can you tell me that you've never written any C code that lacks a sanity check? Because I can tell you that I've never written any Ruby code

    13. Re:So the bindings make a difference? by tomhudson · · Score: 1

      How would you do this in a web environment? Each request comes in independently so how do you deal with all these different instances of queries needing to be serviced? And if you are waiting until you have 1000 different queries, you're going to introduce delays as request #1 has to wait for request #1000 and unless you have a fairly constant, high volume of traffic, you're not going to be able to anticipate the volume of queries. I suppose you could execute the batch every 500ms or 1000 queries, whichever comes first, though that doesn't guarantee the snappiest response for the user.

      Say you have 400 front-facing server threads that are executing ... your back-end process grabs any that have data ready, prepares one large multi-statement query, runs it, iterates through the results, and gives each back it's proper response. Alternatively, you might want to load specific modules into your back-end process that can respond to specific front-end requests that need to generate and process, say, 100 queries - better to do that in one shot than to have php try to do it.

      At any rate, now you have me curious... one of these days I'll have to try batching up queries vs. batching up stored procedures vs. executing independently and letting the server figure it out, then compare the relative performance of each.

      Curiosity is a *GOOD THING* - it's both how we advance the state of the art and how we solve our everyday problems. It's certainly a lot better than most responses, which try to claim stupidity like "running compiled byte-code" - which plainly shows they don't know that "byte-code" is not machine code, and needs further interpretation at runtime. Or like the people who claim that they can solve it with Smarty templates because they're "compiled." Total bullshit. The "rendering time" that Smarty claims is a lie. If you look through the output code, and trace back through to the underlying libraries, you'll see that the timer that calculates page generation time is only started AFTER the supposedly "compiled" code is parsed out by the interpreter, all objects instantiated, and all variables initialized. And the timer ends before the work is done to release all the objects and close the run. In other words, it leaves out the load time (either from disk or an object cache), the construction of the parse tree, all the initialization and ending time, etc.

      As soon as anyone says "compiled templates" I know they don't know what they're talking about. I ask them if they've ever opened up one of their "compiled php templates" in a text editor. They don't think it's possible. Idiots or fools, because they're simply NOT CURIOUS!

    14. Re:So the bindings make a difference? by nacturation · · Score: 1

      Say you have 400 front-facing server threads that are executing ... your back-end process grabs any that have data ready, prepares one large multi-statement query, runs it, iterates through the results, and gives each back it's proper response. Alternatively, you might want to load specific modules into your back-end process that can respond to specific front-end requests that need to generate and process, say, 100 queries - better to do that in one shot than to have php try to do it.

      How does the process grab the data and return the results? Distributed memcached? Some kind of queue system?

      --
      Want to improve your Karma? Instead of "Post Anonymously", try the "Post Humously" option.
    15. Re:So the bindings make a difference? by tomhudson · · Score: 1

      And use of that particular aspect of the class is incompatible with the rest of the class functionality. For example, no prepared statements - which is the only really compelling reason to use mysqli, despite its' higher overhead at runtime. Also, mysqli is not a core part of the language - it's an extension. php itself simply doesn't natively support multiple-statement mysql queries - try it and you'll see quickly enough. Plus, you're still paying the speed penalty for interpreted code, which is what the article is all about.

    16. Re:So the bindings make a difference? by tomhudson · · Score: 1

      No - allocated a 64k buffer and read into it 64k at a time

      If you can go faster by doing syscalls in assembly than using posix read(), your libc implementation sucks

      And just where would one go to get a non-sucky-libc-posix-read() 2 decades ago? And some non-sucky-hardware to go with it? And a non-sucky-posix-compliant-optimizing-c-compiler?

      I know, I'll just whip out Mr. Time Machine and ... no, if I could do that, I'd corner the stock market, start a cult that would make L. Ron Hubbard look like a poseur, and alter the time line so we didn't abandon the moon (hence the cult :-). And I'd make sure that the Motorola 68k series of chips won the war, not the Intel x86. And maybe have Apple buy Microsoft, for the lulz.

    17. Re:So the bindings make a difference? by snemarch · · Score: 1

      Easy now :)

      Which OS + compiler were you on to get behavior like that? Back in the early 90's I was doing Pascal (Turbo6, then Borland7), and routinely had to write chunks of assembly code because CPUs were slow and the compilers sucked... never has the overhead of doing PUSHes/CALL/RET vs. issuing a raw syscall been an issue - assuming that the library routine didn't add a lot of extra junk of it's own. Same when I finally gave up the 16bit world and moved to 32bit dos-extended C++, the to linux and windows.

      Ah, the days when optimizing printf() actually mattered :)

      As for 68k vs x86, oh well. x86 is insanely hacky and there's so much I'd like to see changed about it, but obviously it's been superior to 68k for quite a while, clockspeeds as well as instructions and architecture.

      --
      Coffee-driven development.
    18. Re:So the bindings make a difference? by tomhudson · · Score: 1

      some quick points :-)

      1. Garbage collectors are comparatively expensive at runtime.
      2. "But let's run with it for a second. In PHP, I don't even have to count this part. In places where I do miscount, the interpreter will probably yell at me." ... and you pay a heavy price for that. Interpreters are SLOW. All that extra checking is also slow.
      3. As for php memory leaks, you could have just searched. Here's one. http://bugs.php.net/bug.php?id=37929 Every server child process instance would leak 21 meg. The first time, so if you had 100 children, you could leak 2 gig.

      php is a dog. I still use it, but I'm aware that it's a dog and that there ARE better ways - just that it's always a trade-off between development resources and run resources. For apps running like facebook, it's probably cost-effective to slowly switch pieces from php to c that are going to be more-or-less static.

    19. Re:So the bindings make a difference? by tomhudson · · Score: 1

      How does the process grab the data and return the results? Distributed memcached? Some kind of queue system?

      Each request is encapsulated in a c struct that includes the handle to the socket, the thread id, pointer to the query, pointer to the return data buffer, the type of request (so we know what modules to run to process the buffer), etc. The front-end process can be a plain ordinary web server like apache, in which case it can communicate over a separate socket set at runtime. For example, apache gets the request, stupid slow script requests a connection to the c server on port 12345 (not the real port) - the c server and apache negotiate a new connection on another port, and the server goes back to listening on the original port, while one of the c server threads (there's a pool at startup) gets handed the data. When all the modules in the server (they're all loaded at startup - don't want any delays or screw-ups, but they CAN be dynamically loaded if needed) have finished, the result is sent back to the apache child thread again by tcp over the same port.

      In other words, a conventional server design, but customized to the application at hand, which allows for well over 10x the performance of a php solution. Of course, there's no reason (except laziness) that apache can't be replaced with an identical server for incoming requests, intercept those that the c server can handle with no other intervention, and pass the rest along to a more traditional web server. That's something facebook should look at. This would allow them to gradually, seamlessly, retire servers while increasing workload.

      Or for those parts running on the same machine, use something other than tcp (we actually looked at writing a kernel module to handle most of it, which would have been strange|neat. I played around with it for a bit, but "get this one finished first" ... :-)

    20. Re:So the bindings make a difference? by tomhudson · · Score: 1
      I'm not saying that it was a "necessary evil" to write disk drive code in assembler - I did it to compare the speed with c because I could. Not many people were into assembler even then. I did the same for video access, and of course c was also slower. That's to be expected. Borland products were pretty nice back then. Turbo Assembler, Turbo C, Borland C++. You bought those not just for the compiler and tools, but because the manuals were darned well written (and sometimes funny. The documentation for the sound function was one such case:

      http://community.discovery.com/eve/forums/a/tpc/f/9701967776/m/38319614101

      Found in Turbo C version 2.0 Reference Guide:

      /* Emits a 7-Hz tone for 10 seconds.
      True story: 7 Hz is the resonant frequency of a
      chicken's skull cavity. This was determined
      empirically in Australia, where a new factory
      generating 7-Hz tones was located too close to a
      chicken ranch: When the factory started up, all the chickens died.
      Your PC may not be able to emit a 7-Hz tone. */

      main()
      {
      sound(7);
      delay(10000);
      nosound();
      }
      </blockquote>

      A classic.

    21. Re:So the bindings make a difference? by snemarch · · Score: 1

      Hehe :)

      The Borland IDEs were definitely top notch back then, and the integrated help was world-class... code generation sucked, though, which was even worse back then because CPUs were so slow. For pascal, it became of mix of "Sallys Peephole Optimizer", custom CRT, and hand-written assembly.

      Older versions of pascal had a very cool feature, btw: compiling directly to RAM. This was way before UDMA disks, so it sped up compile/test cycles tremendously.

      Still, as long as you used the lowest-level possible read (_read() rather than fread()), there shouldn't be any advantage in doing disk reads in assembly rather than C. *perhaps* if you went through the trouble of writing a full disk driver and not just calling DOS/BIOS interrupts, but...

      --
      Coffee-driven development.
    22. Re:So the bindings make a difference? by tolan-b · · Score: 1

      "For apps running like facebook, it's probably cost-effective to slowly switch pieces from php to c that are going to be more-or-less static."

      Which Facebook already do when there's a need, so what's your point?

    23. Re:So the bindings make a difference? by tolan-b · · Score: 1

      "Also, mysqli is not a core part of the language - it's an extension. php itself simply doesn't natively support multiple-statement mysql queries"

      The standard MySQL functions are a module too, so by your logic PHP itself doesn't support MySQL. In fact the vast majority of PHP's functionality is modules.

  103. on my top then for stupid it articles by Anonymous Coward · · Score: 0

    Hi

    This is one of the most stupids post about computer I have ever read. Has the author ever written something like facebook (btw i did see http://www.suvi.org/adrbook/ but on the main subject) If facebook would be implemented in C++ it would probably 1) not exist 2) more expensive (means more trees killed) for production and maintenance 3) and probably be crashing several time because of some implementation faults.

    Cheers suvi

  104. Re: FORTRAN by mjwalshe · · Score: 1

    hey don’t nock it I have written billing systems (mostly) in FORTRAN 77 and my employer a major telco sold it as an international product. The bit that wasn’t FORTRAN 77 Was Pl/1G

  105. let it troll by Anonymous Coward · · Score: 0

    hi /. , next time you want to blow up a flamefest, do it better. Why just assuming a conservative ratio of 10 for the efficiency of C++ versus PHP code ? Make it 1/100 , or 1/1000 ! so the trollpost will be at its trollest, and flames will be at their highest. 1/10 is for whimps.

  106. Cheap shot by tp_xyzzy · · Score: 1

    It's a sad day when programmers cannot think any other reason to use c++ than some crackpot global warming co2 theory that doesn't hold water.

  107. Environmental insanity by syousef · · Score: 1

    I hate PHP but there are lots of reasons why PHP might be the better solution. Others have pointed out how ridiculous this is. ASM, C, C++ require more skill, and tkae more time to program with. It seems the moment that lately the moment the environment is mentioned as a factor, not only do all other factors cease to be considered, but all common sense goes out the window. It's like everyone in the room spontaneously turns 12 years old and decides they have the solutions to all the world's problems if only everyone would listen, all the while ignoring the knock on effects and complexities of the real world.

    --
    These posts express my own personal views, not those of my employer
  108. Been there, didn't do that by efalk · · Score: 1

    I think that once your server farm exceeds 100 servers, it's time to start seriously thinking of re-architecting in C. That's probably about the tipping point where your cost of build-out will exceed the engineering costs of switching technologies.

    I invested in a small startup a couple of years ago. We based everything on Ruby-on-Rails, php, mysql, and I forget what else. The bitter lesson we learned -- and what was the main cause of the company's failure -- was that this technology doesn't scale. We nursed it along to 30M records on two servers (the db admins must've been geniuses to coax it that far), but in the end, it fell over.

    We could have saved the company if we could have afforded to expand our servers on our shoestring budget, but in the end, the software infrastructure we were using would have failed us one way or another.

    I've also worked for companies that scaled successfully, and they were the ones that got it. Switched from scripting languages to C++. Switched from MySQL to a dedicated database engine.

    Scripting languages are great for development and prototyping, but for serious production use, you really need to bite the bullet and switch to compiled languages.

    1. Re:Been there, didn't do that by smagruder · · Score: 1

      Explain this to Facebook. Nice fairy tale.

      --
      Steve Magruder, Metro Foodist
  109. Re: FORTRAN by butlerm · · Score: 1

    The exception proves the rule. FORTRAN (like COBOL) is certainly more computationally efficient than the vast majority of languages today, so if you are in a performance / overhead sensitive environment, there can be a lot to be said for such languages. It is just not the sort of thing people normally do without such constraints, because there are other, more modern languages that tend to be more suitable to the task.

    No one is going to write an operating system kernel in FORTRAN, for example, although I have no doubt that it is actually possible.

  110. PHP vs. C++ by Brian+Knotts · · Score: 3, Insightful

    This is idiotic, and is typical of the kind of pseudo-science underlying much of the climate alarmism currently en vogue. Like a lot of things, it is pretty much impossible to quantify which language ultimately uses more power, because of all the variables. As others have pointed out, you might save some power in the deployment of the code, but you would surely use more power in the development of that code. Then, you have to figure out what the total impact of that is, since you'd have more man-hours of coding, using human coders, who sit at desks, in offices, which must be heated and cooled, etc., etc.

    1. Re:PHP vs. C++ by upuv · · Score: 1

      I hear you.

      This couldn't have back fired on this clown any worse. I really hope he didn't make a fool of himself telling everyone he was going to get rick of consulting from this. Cause man he ain't getting anywhere near my work.

    2. Re:PHP vs. C++ by Anonymous Coward · · Score: 0

      This is idiotic, and is typical of the kind of pseudo-science underlying much of the climate alarmism currently in Vogue.

      There, fixed that for ya'. I assume you mean that this is the kind of crap which gets into general-interest magazines like Vogue (as compared to the real research which mostly appears in academic journals).

  111. Since we're making assumptions. by BitZtream · · Score: 1

    I assume the original article doesn't have any basis in reality.

    I can also assume, based on those server counts, what the service does, and what it provides to users, that something about Facebook doesn't have an extremely efficient operation.

    Its fairly obvious that their solution to performance problems was to scale out rather than optimize. There are god knows how many reasons why they could have made that choice, I have no idea if it really was a good one or a bad one, but I'm fairly certain they could be far more environmentally friendly by using C or C++ on their front ends, even if you you take longer to develope it or you hire more developers (which there is no logical reason why you should, unless you hire incompetent C/C++ devs). Probably would cost more, PHP devs are a dime a dozen, competent C devs aren't.

    --
    Persistent Volume manager for Kubernetes - https://github.com/dwimsey/openshift-pvmanager
  112. Re:PHP vs. C+-/* by uassholes · · Score: 1

    Suppose all you care about is making money off some stupid internet idiots, so you start a site called Spacebook.

    Which makes more business sense; buying a lot of computers and paying for a lot of rack space and electricity so you can hire cheap PHP kids, or paying less for hardware and ongoing hardware related costs, but paying more for C programmers.

    I have no idea, but maybe the VCs funding horseshit like MyFace and SpaceBook don't know either.

  113. Unfair by Anonymous Coward · · Score: 0

    It is true that PHP and similar script languages are very slow when it comes to number crunching etc. But serving web pages is not computing fractals or raytracing transparent materials, it's mostly pulling some data from the database and doing some string manipulation before presenting data to the visitor. For most of those things you call libraries anyway, like string library, XML library, SQL library etc. While those calls and some other gluing manipulations are faster in C++, the gain is not that significant (at least not 10x).
    Like others mentioned, if you also consider caching, then performance gain from C++ is really marginal

  114. This logic is crap by Giant+Electronic+Bra · · Score: 3, Interesting

    It would take a really serious amount of in-depth analysis of the server application to even approach knowing what the efficiency impact of using a compiled language vs an interpreter would be on any specific stack. Or even stacks in general. Plus we don't even know what it really means to be "using PHP". What is PHP doing? Is it processing templates, doing just some post or pre processing with some kind of XML pipeline in the middle, how is the PHP deployed, etc?

    It is simply ridiculous to make any assertions and claim accuracy for them. I'm no PHP fan boy by a LONG shot, but I know from hard experience that often a higher level tool which is optimized for a particular job can get the job done quite a lot MORE efficiently than a lower level one that isn't.

    --
    "Malo periculosam, libertatem quam quietam servitutem." -- Jefferson
  115. library routines are compiled by brausch · · Score: 1

    A lot of PHP code is just making function calls to the built-in library functions anyway, and those library routines are all compiled C/C++. If I call a library function from C or from PHP there is some difference in overhead when setting up the call and processing the results but the actual function is likely to be the exact same thing.

    --
    "Almost every wise saying has an opposite one, no less wise, to balance it." - George Santayana
  116. Six things this story didn't say by Anonymous Coward · · Score: 0

    - Server farms take up maybe 0.5-2% of the world's energy. If we're going to stop global warming, we should focus on power plants, cars, and the most energy-hungry industrial processes. McKinsey said 0.5% of the world's energy a year ago, and 1% is cited in some random press release at the top of a Google search.

    - As data center usage grows, other factors will push down energy use per clock cycle: faster and more power-efficient processors (as we move to 32nm fabs, chips that power down idle cores, etc.) and more energy-efficient server farm designs (using weather for cooling, powering some boxes down at night, etc.). The gap between interpreted and compiled will narrow.

    - It's hard to pin down how many server-hours C++ would actually save. PHP might be spending most of its time running code from C libraries (memcached lookups, HTML/XML parsing, regexp evaluations) instead of interpreting PHP. The article doesn't say what portion of the servers are running PHP, and the 10 to 1 efficiency ratio is pulled out of thin air. The server farm might be I/O-bound instead of CPU-bound, and if it's not, it's quite possible that it would *become* I/O-bound if you rewrote everything in C++, preventing any 10-to-1 savings.

    - In capitalism, the amount of energy that will be saved depends directly on how cheap it is to save energy, and there are far more cost-efficient approaches than rewriting everything in C++. Improve the PHP code. Rewrite bottlenecks in Java or C++. Improve the PHP interpreter! Look above the code level to more efficient server/datacenter designs. It doesn't help to suggest cost-inefficient approaches like rewriting tons of code in another language or, for that matter, working with the lights off.

    - What applies to Facebook doesn't apply to you and me. For small to medium sites, the environmental cost of the development effort dwarfs the impact of the servers. That is, ignoring all non-environmental factors like developer salaries, time to market, ease of innovation, etc., spending extra months developing my tiny site in C++ instead of Python or Perl or PHP is just going to use more energy for the development resources than the extra energy the servers use to interpret my code.

    - Even for Facebook, C++ has its own environmental costs. Instead of a bigger server park, you need a bigger office park and more employees driving to work. My energy-saving suggestion for Facebook in its current PHP-driven incarnation: get more employees working from home!

  117. C++. Phooey. by gestalt_n_pepper · · Score: 1

    C++ is an atom bomb in the hands of a chimp.

    I've tested software for about 15 years. I can tell you from experience that THE most buggy, nasty, ill designed applications I've ever tested were written in C++.

    The world is more than performance. For many, many application, the blazing speed of pointers on a local application simply *don't* *matter*.

    Unless I needed to process large chunks of binary data in real time, I'd use anything else but C++. For a web application, I am *sure* that the downtime due to crashes, memory loss, uninitialized pointers and all the other dreck that each and every C++ programmer is convinced never happens to *them* would cost more time, cycles and energy than a perfectly functional PHP application.

    --
    Please do not read this sig. Thank you.
  118. Would C++ Actually Be That Much Faster? by tokki · · Score: 1

    A site like Facebook isn't computing the value of pi or calculating jump coordinates for the Galactica, things that would benefit from a more efficient implementation. I don't know anything about Facebook's site, but many web applications use the application layer to essentially pull data from and send data to databases. Parsing data back and forth typically isn't sped up with C++ or even C that much compared to PHP. All many PHP sites do is draw HTML, and a lot of SELECT, INSERT, UPDATE, and DELETE queries. Hard to imagine C++ having a big impact on that, certainly not 10:1.

  119. even hippies of epSos.de compile PHP scripts by Anonymous Coward · · Score: 0

    The holy PHP scripts are compiled and cached after the first run on a good server system. Then they are preached down to the spiritual RAM sanctuary and run through the CPU to make sure it has got the secret idea about the digital space Jesus.

    The difference in efficiency results from the quality of the compiler. Which can be fixed by improving it.

    Anyway, C++ could never replace PHP on the web, because it is not designed for the web.

  120. ignorance. by unity100 · · Score: 1

    c and c++ are both lower level languages than php, closer to the assembly level. c and c++ can be used to code the compiler that php runs on. php is a CUSTOM language for creating web applications. c, or c++, or anything of their level cant come close to it. because, php was PURPOSE BUILT.

    1. Re:ignorance. by Anonymous Coward · · Score: 0

      c, or c++, or anything of their level cant come close to it.

      PHP doesn't have any special web development features that wouldn't be found in a half-decent C++ web development framework/library.

      because, php was PURPOSE BUILT.

      That means that the people who built it were trying to make it better. It doesn't mean that it actually is better.

  121. Problem with C02 in data center? by DeltaQH · · Score: 1

    Use a nuclear power station. Problem solved.

  122. Bad Math by Flwyd · · Score: 1

    ... assuming CPU cycles are the key bottleneck and not, say, network communication and data access. I'd assume they look at performance pinch points and optimize those. So if the 10% most computationally-intensive code is written in C++ or Java, the savings in rewriting the rest in C++ might be 15%.

    --
    Ceci n'est pas une signature.
  123. The most important part... by argent · · Score: 1

    It's hard to pin down how many server-hours C++ would actually save. PHP might be spending most of its time running code from C libraries (memcached lookups, HTML/XML parsing, regexp evaluations) instead of interpreting PHP. The article doesn't say what portion of the servers are running PHP, and the 10 to 1 efficiency ratio is pulled out of thin air. The server farm might be I/O-bound instead of CPU-bound, and if it's not, it's quite possible that it would *become* I/O-bound if you rewrote everything in C++, preventing any 10-to-1 savings.

    Indeed. Compute-bound code might be 10 times faster in C++, but both PHP and C/C++ will spend the same amount of time waiting for MySQL or PostgreSQL to get back with the results of a SELECT or UPDATE. But even if it's only 2* as fast, on average, that's a lot of servers to save.

    As you say, the main thing to do isn't to recode everything in C++ or C, it's to identify the places where PHP performance is the bottleneck... and look for *well factored* shortcuts that can be implemented in a more efficient language.

  124. How much CO2 is your code producing? by skaralic · · Score: 1

    I was interested in how many kgs of coal a badly written Flash Ad would consume. I did some quick calculations based on the typical Wattage of a desktop and assumed a 10 second view by 1 million people over the course of a year. This assumes that the crappy Flash Ad consumed 100% of a core. I also assumed that all power comes from coal (most of it in the US does). That's a lot of assumptions but should still get us in the "ballpark" for the final figure which, to my surprise, was quite high! I estimated that this would consume around 90 TONS OF COAL! Looking at the figure I am convinced that I made a mistake somewhere in my reasoning, calculations or raw data but I haven't found any problems yet. I would appreciate any interested Slashdotters to set me straight or confirm my work. Here's my blog article with all the calculations on it: http://blog.bit-matrix.com/2009/01/20/how-green-is-your-code/ Thanks.

  125. This story is advertising bate. by upuv · · Score: 1

    This story makes assumptions on system architecture that point blank would just not be true in a large scale deployment.

    Sure C++ is more efficient that PHP. But where does it say that EVERYTHING or even most is served via a php interpreter. In a large scale world dynamic caches and CDN's would have offloaded all of the cachable content and it would have never hit the php interpreter. Guess what a C++, Java, anything else env would do exactly the same thing.

    You would be amazed at how much off load is possible. What you think is dynamic content is usually just a very simplistic dynamic wrapper over large swaths of static content. A seemingly dynamic html is really just a collection of static html blobs that can be held by a cache or CDN close to the consumer and assumbled as a complete html document on the fly by an web aware accelerator.

    These 30,000 boxes that are spoken of are most likely composed of a large verity of purpose specific hardware. Where the purposes are much more diverse than a simple php / mysql combo's. Lets face it. Face book is across the planet and is relatively speedy all across the planet. This implies that a distributed CDN is in place. With local content caching nearest the consumer. Instantly this means we have more purposes than just php/mysql for the hardware. Authentication is usually offloaded by large scale web shops for a host of reasons. So lets add that kit to the list of purpose built. I could go on and on about the various purposes.

    So it's fairly obvious that the statement we could shut off 22K+ worth of machines by simply ( nothing simple about this ) changing languages is just non-sense.

    Plane and simple a large scale web environment is only partially the application hosting equipment. A very large part of the environment is the infrastructure, network, CDN, Caches, accelerators, security, .... equipment. Yes I can write a little fancy web app and run it on my netbook and wow people. It's a whole other matter to scale that up to 10's of millions of concurrent users spread across the planet.

    Lets face it. That amount of equipment consumes one hell of a power bill. I'm positive that "Facebook" has already done an enormous amount of work to reduce that bill. Not for save the planet reasons but for simple dollar reasons. Can they do more. Absolutely. But it won't be a simple we'll just change everything over to this new language this weekend and then hit a bunch of power switches. The amount of power consumed by the massive development work force to write test document deploy this new wonder solution would probably leave "Facebook" in an energy debt for another several years.

    PS. Good luck with that sales pitch if you ever make it near the office doors of facebook. :)

  126. Opportunity cost by Goonie · · Score: 1

    Clearly, it's time for economics 101 again - opportunity cost.

    As a very rough, correct-within-a-factor-of-two estimate, let's assume that the average server results in two tonnes of CO2 being emitted to keep it running. So that's 45,000 tonnes of CO2 a year saved, if the OP's estimate of the difference in speed is correct (which I doubt, but anyway).

    However, if Facebook implements in C++, it's reasonable to assume that they will need to hire more developers, and more expensive developers, than if they use PHP.

    I don't have accurate numbers, but I'll pull them out of my arse here for the purposes of illustration. Let's say that rather than 500 PHP earning $60,000 a year, Facebook instead employed 750 C++ developers earning $80,000 a year. That's 50 million bucks a year in extra expenses.

    Carbon credits on the EU ETS are currently going for around 20 USD. So if you want to prevent the emission of a tonne of CO2, you can go to the EU climate exchange, hand over the equivalent of 20 USD in Euros, and simply rip the permit and not use it.

    So let's say that Facebook spends 10% of the difference in programmer costs - 5 million dollars - on ripping up EU emissions permits. They prevent 250000 tonnes of carbon emissions. That's more than five times as much emission reduction as achieved by substituting PHP for C++, and Facebook still has $45 million in the bank.

    Heck, we could replace "buy carbon credits" with much higher-cost abatement options like "buy Priuses for company cars" and still come out in front.

    Here endeth the lesson.

    --

    Any sufficiently advanced technology is indistinguishable from a rigged demo
    --Andy Finkel (J. Klass?)
  127. Coding C++,savings would be due to the 2015 launch by D4C5CE · · Score: 3, Insightful

    Their decision for using PHP might have to do with being able to get their business up and running now using PHP rather than envisaging go-live a few years down the road with their developer resources and learning curve adjusted to C++ (which in all its well-deserved glory does take its time to master). Probably C's savings in power don't outweigh PHP's savings in manpower.

  128. since when is proof required around here? by ClosedSource · · Score: 1

    "Seriously, is somebody taking seriously the 1 to 10 ratio of the story?"

    Yet the assertion that programmer productivity varies with a 1 to 10 (or even 1 to 100) ratio is accepted without a blink of an eye or the firing of a single neuron.

  129. Isn't PHP compiled to native code and then cached? by idontusenumbers · · Score: 0

    My understanding was that PHP code wasn't interpreted for every page view.

  130. Just in case... by Anonymous Coward · · Score: 0

    ...you're actually being serious, PHP with the Zend optimizer should give you most of the speed of C++ by precompiling at runtime; the "22,500" number also seems pie-in-the-sky optimistic. There is also the need to compile all the C++ code before going "live," which means all of your code needs to be compiled together (instead of updating 1 script); replacing the scripting language with C++ would not affect the power usage (and CO2 footprint) of the database server, and finally you're basing your numbers on the advertising page for Webtoolkit, which is going to be biased against PHP to sell their product. You're also going to have to train your programmers to use WT and C++ instead of PHP (which is a bit easier to learn; I know firsthand!), and pay CO2 penalties to convert all your code over. Not a pretty concept.

  131. Soulskill is the new kdawson y/n? by seebs · · Score: 1

    Why is this garbage even getting posted?

    --
    My blog: http://www.seebs.net/log/ --- My iPhone/iPad app: http://www.seebs.net/seebsfrac/
  132. Questionable Assumptions by WinkingChicken · · Score: 1

    At best, a good case for compiling PHP code. I'm not sure the assumptions are sound at all: 10:1 ration? PHP code is dominant code executed? I'd bet most of execution is in database, and that is surely executing compiled C/C++.

  133. Assumptions, eh? by nathanh · · Score: 1

    Let's assume that C++ is twice as hard to code and maintain as PHP. Let's also assume 200 man years of work went in Facebook. Let's further assume there are 50 maintenance workers and each worker commutes 50km per day, 220 days per year.

    Cars average 200 grams of CO2 emissions per km, so writing Facebook in C++ would have produced 440,000 more tonnes of CO2 than the PHP workers. Each year that goes by, the C++ maintenance workers would have produced 110,000 more tonnes of CO2 than the PHP workers.

    Sounds like a good argument to dump C++. As if you needed any argument other than "it's C++"!

  134. It isn't just one server by Colin+Smith · · Score: 3, Insightful

    Running a server is cheap.
    Paying a developer is not.

    Civilisation is largely about the multiplication of human effort through the consumption of energy and automation. So, we multiply this developer's effort by a couple of thousand when running one machine and then do the same on another several hundred machines beyond. Each costs several thousand dollars to purchase and several thousand more every year in electricity, in cooling, networking, management and maintenance.

    So, the effects of developer incompetence are also multiplied several thousand times often across hundreds or thousands of systems. Millions if we're really lucky.

    So it isn't just one server, it's just one extra datacenter. It often pays to hire better people.

    running a server for a day - $1

    You think you get a real server for that? You get a tiny division of a server for that kind of money.

    2) why doesn't these big server farms start looking at migrating code from PHP to C or C++ when the PHP+web design is solid?

    The network effect. They migrate to Java instead.

    Speed to delivery is nearly always primary importance.

    Indicating speculative projects and disposable code.
     

    --
    Deleted
    1. Re:It isn't just one server by crispytwo · · Score: 1

      So, the effects of developer incompetence are also multiplied several thousand times often across hundreds or thousands of systems.

      Agreed, but still, incompetent C++ code exists too. Language choice is not important when dealing with incompetent developers... You might even argue that getting bad C++ code is easier to do than bad PHP, or Java code, but we're splitting hairs there.

      You think you get a real server for that? You get a tiny division of a server for that kind of money.

      A month's cost over to an hour for sure... but I messed up. So, to correct that $240/mo -> $8/day. Still $8 is a lot less than paying developers one hour in NA.

      The network effect. They migrate to Java instead.

      I don't follow you here. Sure, it could make sense to move to Java too... but why, if one wants the fastest possible code?

      Indicating speculative projects and disposable code.

      Yup. We are talking website stuff... Aren't we? ...

      All this is about writing code in C++ for websites. It can be done, but it is expensive up front. Sure it 'can' save you money later in operating costs. But that's not where there cost really is. I do think it would be prudent to offload to efficient languages when something is no longer speculative, but that doesn't occur until something matures. Even then, it has to have a certain scale to matter. A single server running PHP managing the load won't change anything much if you rewrite it to use C++ on a single server and it manages the load.

    2. Re:It isn't just one server by dkf · · Score: 1

      It often pays to hire better people.

      It does. It also pays to have them using the right tool for the job. Where you (and the original article) fall down is in proving that C++ is that right tool for this particular job. Carbon efficiency is definitely only one aspect of many there. From the business's perspective, there's no point in being carbon efficient if it leaves you so inflexible that you lose marketshare and cease to be viable. Far better to invest in power sources that reduce the carbon intensity of the business while still permitting flexibility. Oops! Solar power would let them avoid C++!

      --
      "Little does he know, but there is no 'I' in 'Idiot'!"
  135. Your Hummer uses PHP. by ElboRuum · · Score: 1

    Clear evidence.

  136. Not really... by Chris+Snook · · Score: 1

    After a recent change in hardware platform for new acquisitions, Facebook was surprised to get a speedup from RDDR2-800 memory vs. FB-DDR2-667 memory, because many of their apps are actually memory-bound. They're a major user of memcached, so the real limiting factor on how many servers they can power down is how much RAM they can stuff in a server. The CPU utilization comes somewhere after memory/disk throughput/latency in power conservation considerations. Sure, there's a small marginal difference in how much energy they burn through on PHP code vs. C++ code, and a small marginal difference in how much RAM they need free for PHP vs. C++ code, but for the effort it would take them to switch to C++, they could save a lot more energy by optimizing how they use memcached. Which is exactly what they're doing.

    --
    There's no failure quite as dissatisfying as a complete and total solution to the wrong problem.
  137. Fart vs PHP by Ego_and_his_own · · Score: 1

    I think if we managed to sustain a fart at least once a year we would putt less CO2 for a year than PHP cause for 10 years. Not to mention that how much PHP with all that Open Source phenomenon behind it save lives and nervs... PHP affected more on suicidal numbers that anything in C++ Web development world...

  138. One word by fast+turtle · · Score: 1

    Noscript :>)

    --
    Mod me up/Mod me down: I wont frown as I've no crown
  139. Fart vs PHP by Ego_and_his_own · · Score: 1

    I did know that I will find it: "The average person farts 12-18 times a day, producing about 45 mL of CO2 and 45 mL of CH4 per day, or 16.43L of CO2 and 12.78L of CH4 per year." Source:http://envirostats.digitalcitizen.ca/2007/07/19/0172/ Here is interesting part: "At Standard Temperature and Pressure (STP), 1 kg CO2 is 509.1L, so the 284.9L per year is only 0.560 kg CO2 per year. This is less than the amount it takes to run your computer for a year (0.705 kg), and a tree would only have to spend 17 days per year “sniffing” the greenhouse gases in your farts all year to carbon neutralize it." Considering that not evry peroson on world has computer ( and uses PHP) conclusion is not discussable. Moderator are you one of people who always giggles when someone mention fart or similar word?

  140. Re:Java vs PHP by Phrogman · · Score: 1

    Well I am biased in that I *like* PHP, despite its flaws. However, speaking to the argument that Java might be a better choice, I did work on one project which we essentially completed in PHP as a first draft, and then the lead designer decided that PHP wouldn't be scalable enough (i.e. he decided he didn't like it, since he had no evidence to point to), and we rebuilt the whole thing in Java instead. PHP development time: 6 months, Java Reegineering: 2 years more.
    The end result was efficient and made good use of Java's strengths, but I can't honestly say it was a superior product, and the additional development time spent on adapting it to Java could have been spent revising and improving the PHP version 4 times over.
    PHP is quick to develop it, quick to make changes to, and good enough for many jobs. There is a reason why sites like Facebook are using it so heavily. Purist programmers may not like it for a variety of reasons that may be entirely justified, but in many cases PHP is the right tool for the job and that is what should really matter. Java is also an excellent tool, but I think the development time is greater in the end, and the results are not necessarily all that much better. It likely comes down to a matter of preference, as other languages like Python or Ruby would probably be just as useful in the end.

    As an aside, why does the OP not mention that you can write your own extensions to PHP in C++. Wouldn't that be a better option where you see code that is running too slow: concentrate on only those bits where it might really have an effect.

    --
    "The first time I got drunk, I got married. The second time I bought a chimpanzee, after that I stayed sober" Arian Seid
  141. Facebook. by Anonymous Coward · · Score: 1, Insightful

    What about just turning off facebook, the entire thing is a collosal waste of time. And while your at shoot all the users as most of them are idiots who are a waste of space.

  142. oh boy... by lien_meat · · Score: 1
    This guy is pulling numbers out of his butt, assuming random ratios of speed differences...
    I know it's already all been said but really...the author needs to try this:

    Program a small application in php, and one in c++. All the data must be stored in a database, on a remote machine (which is the way it would be done for a huge site). Now, hardcode in some data for your first benchmark of php vs c++ to get an idea for raw php vs c++ performance doing the same task, now, comment all that out, and get the data from the database, and time that. Guess what, I bet the times become pretty darn similar in the latter test. No, php isn't going to be QUITE as fast...but it's gonna be really close for REAL web-application type workloads where latency from your sql server and loading all the other page content come into play. Your clients are never going to notice the difference on the majority of applications, and I don't believe that most time is spent processing php or c++ code on a web application either. It's waiting for the DB, and uploading content to clients. If you truely are doing extremely data heavy tasks and lots of floating point math or something, then yes...C++ is probably a better tool, but even then, there's no reason not to use php for the non-data heavy stuff...

    I know I'm just a youngster web programmer who only graduated from college a while ago and who deserves little respect on slashdot compared to some of you, but I do have a decent amount of experience with quite a few programming languages. I learned C++ first, and know it pretty well for someone who doesn't use it constantly any more. I think I'm very very good with PHP...and so does my boss. Given that information, I have something to say.

    If someone told me to program an entire web application from top to bottom in C++, I'd probably quit on the spot, and walk out laughing all the way to the parking lot. I like C++ for lots of things, but there is no way in hell you would EVER get me to program an entire web application in c++. It would take 10x longer at LEAST to develop than it would for me to do in even Java, with which I actually have less knowledge of (but still a good working knowledge of), and I don't consider ideal for web apps. The debugging for C++ on something like that would probably drive me completely insane. I say me, because I'm assuming that I'm building this web app and only me...like I can do very quickly in php or python or nearly any other language that does web stuff well, otherwise it would be me and all my co-workers.

    Languages that are traditionally used for web development are used for a reason...and it's not how fast/efficient they run. It's for the difference in expense of the developers (HUGE factor really), for how well the language suits the web in it's core libraries, and how well it integrates with web servers, database abstraction libraries...well I could go on forever really. I'm not saying that C++ couldn't get libraries built for it that made its appealing as say, ruby (on rails), php, or python, but lets face it, it would take a very long time to get to that point where everything was as seamless and easy as it is in current web languages...not to mention getting hosting companies to let you run a c++ app YOU programmed on their servers (they'd have to be stupid...really freakin stupid). C++ will just never be popular enough for web stuff to be attractive to developers...that's the bottom line. Lack of efficiency is such a tiny price to pay compared to these other factors.

  143. Wooden Carts by jamesccostello · · Score: 1

    This is like saying that we should use those medieval wooden carts to ship packages across the US. PHP works in many places where cpp fails to deliver (no pun intended with relation to my previous statement).

  144. Real numbers and graphs by PassMark · · Score: 1

    We have done the actual benchmarks, and the original post matches our experience.
    PHP gives processing times of around 1 second (for a search function) and C++ code via a CGI gaves times of 0.1 sec. A ten times improvement.

    Graphs and numbers are here,
    http://www.wrensoft.com/zoom/benchmarks.html

    Further when we switched to FastCGI we saw another 5 fold improvement, after optimising the code for FastCGI.

    So I would believe a 50 folder improvement should be possible by going from PHP to FastCGI (and rewriting code to suit a FastCGI)

    1. Re:Real numbers and graphs by FlyingGuy · · Score: 1

      Lovely graphs, really they are. Uhmm small problem, your benchmarks are completely and totally irrelevant to the subject at hand!

      The vast majority of what PHP is used for is to generate web pages, not search through a hard disk of hundreds of thousands of files for a word or phrase, and further to use PHP for that would be seriously horrible technical decision.

      As a matter of fact CGI is irrelevant for this for that matter.

      Please at least use the language for its intended purpose and all the other languages for the same purpose if you are going to be making comparisons.

      --
      Hey KID! Yeah you, get the fuck off my lawn!
  145. Scripting not programming±±? by fyngyrz · · Score: 1

    ...scripting (which isn't "real programming" - it's scripting...

    Aw, c'mon, that's just harsh. It's programming, it's just one type of programming. Speaking as a C and assembler fanatic, but fan of inter-compatible versions of Python and burner-at-the-stake of perl.

    Scripting is nice just to whip things up and do proof of concept in, too.

    On-thread, I agree that the difference here is quite high (for PHP against C), it'll vary for other languages. There's a nice table of relative speeds here (and the argument about what the language is doing, I don't buy... in my experience, things tend to remain somewhat relative):

    Multi language simple fractal benchmark

    These are obviously not the times you'd get for web ops, but I am of the opinion you'd find a similar curve, similar time relationships, for any general program. Which is to say that not only is PHP slow, it's slow for everything, which means it is an inefficient use of system resources in busy environments. Lots of cycles for not much done, which means programs that are loaded longer and resources that are tied up longer -- regardless of the underlying DB transactions, too - the DB is running on the same server, those cycles could have been DB cycles. And if not, more apps could have been running with the others out of the way sooner and/or not consuming CPU time. Waste is waste.

    --
    I've fallen off your lawn, and I can't get up.
    1. Re:Scripting not programming±±? by tomhudson · · Score: 2, Insightful

      Yes, it is harsh, but anyone who has not programmed in c and assembler, and then spouts off nonsense about how php can't possibly be 10x slower, doesn't have the programmer mind-set.

      That mindset includes understanding the runtime environment - which means knowing the limitations of your tool - in this case php. That means you'll not "have" to do something in php because "when all you know is php, everything looks like it needs a script" rather than a different tool.

      Case in point - generating test data. Say you want half a billion examples stuffed into a db. You can run a script, which will take forever, or you can write it in c. Real-life example - a "world" measuring 8k x 8k cells, with each cell also measuring something like (iirc) 100 x 80. You can write a script to generate all that, and it will take a week to run (actually, it would have taken 220 hours). Or you can take an hour to write a similar program in c, let it run during lunch (a longish lunch - an hour and a half), and get back to work in the afternoon.

      That's why I'm a bit harsh on the "script it!" crowd. They're not very imaginative or curious, or they would learn c - it's not THAT hard.

    2. Re:Scripting not programming±±? by gullevek · · Score: 1

      If the DB can't keep up with inserting a billion examples, all the fast C code won't help here either.

      --
      "Freiheit ist immer auch die Freiheit des Andersdenkenden" - Rosa Luxemburg, 1871 - 1919
    3. Re:Scripting not programming±±? by Alpha830RulZ · · Score: 1

      While I'm sympathetic to your overall point, I can't help but wonder about your example. I used python to create a 500 M record test dataset this past week, and we were in in the range of 20 minutes, not 220 hours. You can write bad code in scripting languages as well.

      --
      I was taught to respect my elders. The trouble is, it's getting harder and harder to find some.
    4. Re:Scripting not programming±±? by adamchou · · Score: 2, Insightful

      While you're churning away your super optimized C code which runs faster than god knows what and finally debugging the library to handle your super cusotmized tcp/ip replacement, I'll have already rolled out the application you wanted to do, but in some "non-programming/scripting" language like PHP, Ruby, Python, or hell... even Java.

      There's a purpose for every language out there and frankly, writing some form of code to have a computer perform specific tasks is called programming. So please contain your ego instead of going off and spouting things like...

      scripting (which isn't "real programming"

    5. Re:Scripting not programming±±? by testadicazzo · · Score: 1

      Sure, but the point the original poster is trying to make is, when you're running more than a thousand servers to support your app, maybe it's worth thinking about optimization. Wouldn't you agree?

    6. Re:Scripting not programming±±? by Anonymous Coward · · Score: 0

      Going AC here to avoid dealing with disgruntled co-workers ;-)

      In my experience it is not so much the language itself as it is that many programmers in corporations never learned to program but just learned a programming language. They do really stupid things since on a one user system with a small test database it all works fine. Then when it goes to production with multiple users and on production size databases, it becomes very slow and they start adding CPU power.
      Usually it would have been very easy to prevent if they knew much better what the consequences of their programming would be in production. It requires more knowledge on what exactly happens, on architecture of the solution (i.e. do I let the RDBMS handle a certain process or let a application server handle a process), the cost of asynchronous versus synchronous etc.

      There are many reasons why it makes sense to choose PHP over C and accept that it will use much more raw CPU power and memory. Speed of development is one of them. But that is no excuse for not knowing your trade and just learn the language that is popular right now and has the highest amount of job openings in Monsterboard.

    7. Re:Scripting not programming±±? by tolan-b · · Score: 1

      I'd agree with that but the point is that with the vast majority of web apps the bottleneck is the database. There are usually far more gains to be had in optimising your DB and DB caching (including row to object transforms if you use OO with a relational back-end) than there is in switching your programming language.

    8. Re:Scripting not programming±±? by chthon · · Score: 1

      And the issue I have with the word 'scripting', is that people never called programming in Basic scripting, even if it was interpreted (I think that Basic compilers only appeared in the eighties, I could be wrong here of course).

    9. Re:Scripting not programming±±? by tomhudson · · Score: 1

      It depends on what type of data you're trying to generate. Terrain maps that actually "make sense" are a bit more complex than completely random data like $RANDOM_LAST_NAME + "," + $RANDOM_FIRST_NAME, for example, so once you generate a grid, you've got to make it sane, and it's got to have a pattern that looks realistic to a human. You can't for example, have a river that just goes in a circle.

    10. Re:Scripting not programming±±? by tomhudson · · Score: 1

      If the bottleneck were the database, you couldn't make your app 10x (or even 2x) faster by switching to c. The bottleneck is the interpreter, not the db.

      The people who claim the bottleneck is the db haven't tried to benchmark the difference in speed between using php and using c to access the db, or they'd know that it's like night and day.

    11. Re:Scripting not programming±±? by Alpha830RulZ · · Score: 1

      Fair enough, and I agree with your prior statement, which was that C is not hard to learn. I'm old enough to have worked extensively in C because we didn't have the more modern alternatives. Even C++ was new, dinosaurs were still leaving tracks in the mud, and Kernighan was still dating.

      I have not recently encountered many problems where I needed to take on C or C++ to create a sufficiently efficient solution. I have nothing against C, indeed I loved working in it back in the day. I never worked with C++ to become comfortable with the libraries, so I just steer clear of it. Java/Scala have worked well enough for anything that was intensive, and Python is just easier for everything else. It's a rare problem in my world where developer efficiency isn't a primary goal, and that hardware can't be used to solve the rest of the need for speed (assuming a reasonably efficient implementation). I know there are many cases where that isn't true, they're just rare in my work.

      --
      I was taught to respect my elders. The trouble is, it's getting harder and harder to find some.
    12. Re:Scripting not programming±±? by tolan-b · · Score: 1

      It's pretty simple to profile an app and see it's spending most of its time waiting for the DB. I've done this with our CMS, which renders pages on first request and then caches various cacheable parts of the page until they're invalidated by some action. The DB is the bottleneck, it's easy to see, just see how much time the app spends waiting on the database query function.

      A well written web-app really shouldn't be doing much processing for each page view, typically they're extremely cache and DB intensive if they're written right. We're usually not talking about apps that have to do heavy maths or anything like that, they're mostly pretty front ends for previously entered data. Database read to write ratio tends to be in the region of 10:1

  146. Loose typing and dynamic data structures by bigtrike · · Score: 1

    The problem is that when you've got poorly defined data structures and typing most of the overhead can't be compiled out, as your C/C++ program still needs to deal with all of the indirection and type conversion. Due to PHP's loose typing, the type of a variable at any given time cannot be predicted, as it may vary due to user input. The problem is that the language provides no mechanism of forcing a given variable to any type or creating any data structures. Even in compiled code, even a simple addition of 1 to an integer must involve pointer dereferencing and lots type changing bounds checking.

    The code could be optimized if the type of a given variable could be forced for its entire life in scope, which would allow to compiler to avoid a lot of repetitive logic for each operation. Specifying strict data structures would also be very helpful, as the compiler could then avoid finding the pointer in a key hash and instead it could hard code the offset from the start of the structure.

  147. Distraught about PHP by kriston · · Score: 1

    I'm distraught about PHP and its efficiency. Unless you do some kind of guru magic, every click on your server is interpreting not only the screen you're visiting but all the libraries it requires to load itself. The computers spend nearly all of their time interpreting the same code over and over for each click. The analysis is sound and points out the fallacy of using interpretive languages in ways they aren't intended to be used. On the bright side, at least they aren't using Perl under CGI.

    --

    Kriston

  148. C++ is officially back in fashion by Anonymous Coward · · Score: 0

    A few years after processor designers ran face first into the power wall we're starting to see clearly the age of performance challenged anything goes abstraction absurdium has come and gone.

  149. Pike? by belmolis · · Score: 1

    Out of curiosity, does anybody use Pike, at least outside of Scandinavia and Germany? I've only written toy programs in it, but it seems quite nice and to be pretty efficient. It's C-like, but with many of the nice features of dynamic languages. (Okay, I admit it, what I really like is that it allows binary literals.)

  150. Takes 20 times as long to code a website in C++ by smagruder · · Score: 1

    That's my guess of a stat. I'll keep with PHP, thanks.

    --
    Steve Magruder, Metro Foodist
  151. Bad math by Anonymous Coward · · Score: 0

    Oh the joys of bad math.

  152. But what about the environmental impact of... by Zadaz · · Score: 1

    But what's the environmental impact of making up 'facts', turning that into smoke, and then trying to blow that smoke up my ass?

    A lot of people are getting bent out of shape by this thing, but I can't see how anyone can begin to take it seriously. The whole thing is so completely bogus and made up that giving it anything but a good hearty laugh

    Thought I'd love it if my randomly made up factoids merited a front page story on Slashdot.

  153. Re: Server side overhead with AJAX applications by butlerm · · Score: 2, Insightful

    Ergo, it is going to reduce the processing necessary on the server to do any given job

    Any given job, yes. But if there are a lot more "jobs" (i.e. more requests that require server side processing), the efficiency of the language used on the server side tends to become more critical, not less, especially if the per request overhead is significant, something that happens to be one of Facebook's primary complaints about PHP.

  154. How to really cut down on the CO2 Emissions by Anonymous Coward · · Score: 0

    And how much would CO2 emissions be reduced if people just stopped fucking wasting their time Facebook and MySpace?

  155. Not quite by butlerm · · Score: 1

    All you have demonstrated there is that statically compiled implementation A of a regular expression library is more efficient than statically compiled implemenation B of a regular expression library. This is a contest that PHP cannot win. The implementation PHP uses is not written in PHP, but rather something like C.

    That said, programmers who have better alternatives do not rely on regular expression parsers for casual processing in performance critical code. Regular expression engieer tend to be much slower than the alternatives in any compiled language. Of course hand coding the equivalent code takes longer.

    You will never find a competitive compiler that uses dynamically parsed regular expressions to do language parsing for precisely this reason. It would slow the parsing phase down by a factor of ten or more due to two problems - first the regular expressions themselves have to be parsed, and then the resulting state machine has to be interpreted. In other words regular expression libraries are a microcosm of the situation with PHP itself - provided the patterns are known ahead of time, hand written native code to do the same thing is much faster.

  156. time and maintainability by j1m+5n0w · · Score: 1

    How much does a typical developer cost versus a potential saving of 1000 servers? What is the human to server runtime cost ratio? And how many developers would it take to actually replace and maintain php with C/C++ code? (It would probably take more than the number of PHP programmers, and they'd probably cost more per person, and I question whether it would be as maintainable)

    In any case, it wouldn't be as simple an analysis as the article implies. That much is certain.

    I think most of the analysis I've seen so far implies that it's a simple cost tradeoff - more programmers versus more servers. It's more complicated than that, and you have identified one of the reasons why: maintainability. The kind of programs Facebook needs written are just plain easier to write in PHP than in C or C++, for many reasons (though PHP was probably not the best language they could have chosen, it's not an awful choice, either). If they wrote it in C or C++, not only would it be more expensive, but (and this is the important part) it would take longer to write and test. Web companies can't afford to waste a couple years re-writing their core infrastructure. They also can't afford to be stuck with a tool that's hard to modify.

    Also, it's not as if Facebook is an all-PHP shop. They've invested a lot of effort writing an open source tool called thrift, which allows programs in any of the (12 or so) supported languages to communicate easily with each other. If they decide it makes sense for them, they can change languages.

  157. re: half a brain by j1m+5n0w · · Score: 1

    I think the world is better off when people use the language that meets their needs rather than the language that makes them look smart.

  158. 1/2 the speed for any language? by butlerm · · Score: 1

    With modern techniques, just about any language can be sufficiently compiled to run within 1/2 the speed of C

    If only this were true. In the real world, Java is dead on the client side precisely because a large Java application cannot be compiled (let alone JITed) to come within half the speed of an equivalent application written in C/C++. Dynamic languages are worse in the sense that they tend to compile to native code much more poorly than a statically typed language like Java, although this is indeed changing.

    When you can run a word processor written in Javascript on a thousand page document with 1/2 the speed of a word processor written in C/C++, and not wait forever for it to start up, we will know that dynamic language compilers have arrived. I would be impressed if someone could do that with Java, especially without resorting to expedients like SWT, to say nothing of library after library of C support routines - stuff Java simply (currently) cannot do with any reasonable speed, no matter how good the compiler is.

    And it need not be said that no one is going to write a word processor in Perl, Python, or PHP anytime soon, although once the appropriate JITs are out there it would be interesting to see someone try.

    1. Re:1/2 the speed for any language? by Cassini2 · · Score: 1

      Take a careful look at what your Java program is actually doing, in whatever example applications that you have. If you then rewrote the same program in C++, to do exactly the same things, then it would be dead slow too. In fact, when certain widely encouraged programming practices are used, it can cause C++ to be very slow too.

      If you sit down and rewrite the Java program so it doesn't do all the "idiotic" things that no normal C programmer would do, then Java is surprisingly fast. Hence the variability between different peoples opinions of speed in Java. Personally, I don't like the way Java makes it difficult to get an assembly printout. As such, I don't know when the Java compiler is making fast code or slow code. I think that is the real problem with Java is that it is so abstracted from real hardware that few programmers have any idea of what it is the average Java program really does.

    2. Re:1/2 the speed for any language? by butlerm · · Score: 1

      If you then rewrote the same program in C++, to do exactly the same things

      If one rewrote a large C++ program so that it didn't use any non-scalar value types, never used arrays of structures, never placed anything other than scalars and pointers on the stack, and relied exclusively on garbage collection for memory management, even for temporary variables, then it would probably run as slow as a Java program compiled ahead of time too, if not as bad as a Java program that has to be JITed before it comes up to speed.

      That is not to say that Java can't be very effective in a server environment for a large class of applications. And certainly a good Java programmer has to be aware of what is going on at a relatively low level with regard to dynamic allocation, garbage collection, etc.

  159. Fuck facebook by Anonymous Coward · · Score: 0
  160. no by OrangeTide · · Score: 1

    the advantage of C and C++ is that it is not dynamically typed. picking some language that has similar syntax but is dynamically type makes it no different than picking python, ruby or php. Other then you get to suffer with a system language's syntax instead of the niceties of a script's syntax.

    --
    “Common sense is not so common.” — Voltaire
    1. Re:no by belmolis · · Score: 1

      Actually, Pike is not dynamically typed. Although it has other features of dynamic languages, it is statically typed, with a twist, namely that it uses tagged unions. That is, a variable may be assigned a union of types.

    2. Re:no by OrangeTide · · Score: 1

      Oh that's not so bad then. I still have a hard time finding debuggers for these scripting languages that work as well as the mature tools in the compiled world. Perl debugger is quite good, but I'm not endorsing perl in any way. pdb(python debugger) seemed to confuse everyone that I tried to show it to, so it gets a big thumbs down from me.

      --
      “Common sense is not so common.” — Voltaire
  161. Re: FORTRAN by mjwalshe · · Score: 1

    well at one time some of PR1MOS was in fortran but i think the later versions where more PL/1G

  162. Compiled PHP? by softegg · · Score: 1

    I have not tried this, but there is a thing called PHC ( http://www.phpcompiler.org/ ) that purports to compile PHP code. Has anybody tried it? Does it work? Is it useful?

  163. paint it black? by Anonymous Coward · · Score: 0

    aren't they going to have more eco-friendly results with a black (instead of white) background on the html pages they produce?
    that's 5 minutes of work and a zillion pixels on client screens that don't light up.

  164. Nah, Java is the real killer by SmallFurryCreature · · Score: 1

    Because I know this Java guy and he got the foulest breath you ever smelled before you nose shuts off.

    And since I am a PHPer and god's gift to woman kind (he decided they could do with a laugh) we can now safely conclude that 1. PHP 2. C++ 3. Java 999999999999999. ASP

    The original article is just silly however, C++ is overkill were you often end up writing stuff that has already been written and been written better then you can ever do yourself in the time a typical web project has.

    And that the author is full of shit can be clearly proven that he has NOT approached facebook with a sample of new code that would safe them a fortune. I myself have made very good money helping companies reduce their server needs, if he can shut so many servers of with his code, he can earn millions. But he isn't, is he? Perhaps because as a C++ web programmer he ain't used to actually getting a working site out on time and on budget that can be maintained easily to deal with rapidly changing demands?

    I seen "real" programmers completly loose it on web-projects. They want to do design and analysis when the time to setup the schedule is the time you got for the entire project. Yeah yeah, if you give them a year or two, the product is no doubt 100% better then the 2 weeks PHP job, but the web moves a bit faster then that boys. I have seen a project where a traditional programmer sought out a framework solution that was just perfect. Nobody had used it but no problem, he had setup a 1 month training schedule for everyone. The entire project was supposed to be delivered in 1 month.

    PHP works people because it works FAST. It allows you to drill straight down to the thing you want to do with a website rather then first having to develop your own solution for things that have already been done. Yes, this ease has lead to a LOT of PHP developers who couldn't code their way out of a paper bag, but this is like saying that because there are so many idiotic windows users, all windows users are idiots. Or indeed me saying that because I only seen C++/Java developers who over-engineered, all C++/Java developers do this.

    And as for speed, when you use compiled PHP, it really ain't that much slower. Sure, you could optimize the hell out of your website with C++, but only if you spend ages doing this, making your site obsolete by the time it launches and extremely hard to adapt as demands change.

    --

    MMO Quests are like orgasms:

    You may solo them, I prefer them in a group.

  165. Re:so where is the example of a company doing this by Anonymous Coward · · Score: 0

    You forgot that you can always do it in a FPGA, and if that isn't fast or efficient enough just build an ASIC

  166. The real picture by Anonymous Coward · · Score: 0

    http://naspinski.net/post/AspNet-vs-php--speed-comparison.aspx

  167. OO is stupid by Anonymous Coward · · Score: 0

    Actually OO guys routinely make things ambiguous.

    Three lines of code becomes 60 after several classes have become established.
    Instantiate is such a spontaneous word to them. Every 3rd word out of an OO guy's mouth is instantiate.

    Damn Microsoft people.

    So I proudly write int int1, int2 and int3 just to piss you off.

    Reminds me of Debian people with their packages of packages.

    Ar sucks. Just use Tar.
     

  168. The syntax ... by jotaeleemeese · · Score: 1

    "The syntax is fairly straightforward and familiar, being a typical mishmash of shell scripting, C and perlisms"

    How can somebody contradict himself in the short space of a single sentence?

    --
    IANAL but write like a drunk one.
  169. Speed of interpretation isn't the only bottleneck by WoodstockJeff · · Score: 1

    Comparing the speed of PHP (or Perl, or Ruby, or ???) to a compiled application in a site like Facebook is an invalid comparison; so much of what needs to get done involves outside processes. Pesky little things like exchanging data with an SQL server.

    Years ago, I wrote a highly-optimized C program to interpret input data and save it to a database. C was used because the interpretation involved a lot of bit-based (rather than byte-based) manipulation. It was very fast. But, a couple of years ago, I needed a one-time modified version of it for a project, so I developed the temporary program in PHP instead, since the changes to the C program would take longer than I wanted to dedicate to the process.

    Surprisingly, the bit-wise manipulation in PHP, while significantly slower than that of the C program, was not a significant factor in how fast the conversion ran. What should have been a 100-200% increase in run time was less than 5%, due to the overhead of the database inserts. For a program that runs once or twice per day, the added overhead was inconsequential, so the next revision of that program was in PHP.

    Could Facebook shut down thousands of servers if all their code was converted from PHP to C++? Doubtful. Maybe a hundred or so, but not tens of thousands, as claimed.

  170. A reduction of CO2, or an increase? by Anonymous Coward · · Score: 0

    The premise of high-level scripting languages is they save programmers' time, and that programmers' time is worth more than computers' time. Let's ass/u/me it's true (yes, I know some people will disagree that high-level languages really save programming time).

    If you're going to talk about how much would be saved by switching to a lower-level language, then you should also talk about what it would cost, i.e. how many people would still be working on those applications and their pay rates and other expenses.

    And if you going to measure CO2 cost of PHP, then don't forget to measure the C++ developers' workstations' impact, compiling several times per day to develop an application whose PHP equivalent is already running. And do these developers commute? Are the lights on in their offices? Should you measure their entire carbon footprint during the increased development period? (Probably not, but some of it would surely apply.)

  171. Get it done vs. get it done right by rgviza · · Score: 1

    Get it done wins every time. Power is cheaper than a competent C++ coder's time and time to market is shorter for PHP. I'm not saying it's right, it's just reality kicking idealism's ass again. /shrug

    --
    Don't kid yourself. It's the size of the regexp AND how you use it that counts.
    1. Re:Get it done vs. get it done right by rgviza · · Score: 1

      Oh then there's the fact that most web code has a very short lifespan so the investment in C++ isn't always worth it in the long run...

      --
      Don't kid yourself. It's the size of the regexp AND how you use it that counts.
  172. Web development is mostly String processing by fuzzylollipop · · Score: 1

    and as much as I had to say it PHP is about as efficient as any other language that has a C based runtime at String processing. There is probably NOTHING to be gained by adding the complexity and cost of a lower level language like C++. Now re-writing it in Erlang, that might get you something ;-)

  173. Writing Facebook in C++ by Anonymous Coward · · Score: 0

    The reason Facebook is not written in C++ is because they would still be writing it, so we would not have facebook.

  174. Some real benchmarks by Anonymous Coward · · Score: 0

    I think, these benchmarks of C++ (CppCMS) vs PHP based web systems are more then relevant: http://cppcms.sourceforge.net/wikipp/en/page/benchmarks

  175. morhook by Anonymous Coward · · Score: 0

    Do you think the wikipedia should be written in C++ too? My G-O-D!!

  176. The future of PHP by butlerm · · Score: 1

    The premise of the article is right on target, in terms of power efficiency for the entire front end. You are right, however, that if power consumption or hardware overhead is a sufficient problem, you could probably gain a marginal amount of performance by going to C instead of C++, although far short of the reduction one could obtain by making the first step. The question is one of balance.

    If your requirements make it optimal to run a language that is running behind the state of the art in interpreted languages by nearly three decades because it is easier for some people to learn, that is great. Compared to something like Applesoft BASIC, which actually started out with an intelligent, highly optimized design (byte code even!), PHP started out as a first class hack. And like most first class hacks, short sightedness in the original design tends to cripple all future versions, even when it is far past time for the system to "grow up".

    And that, unfortunately, is why the future of PHP looks approximately as bright as the future of Perl. The duct tape of the Internet. Not that there isn't a sizeable niche for that sort of thing.

  177. Rabid Green Monster by manlygeek · · Score: 1

    Wow, Gratz to the submitter of this article. This is one of the most rabid and foolish examples of "going green" I've seen. PHP is certainly not the most efficient language in terms of run time resources. But you have to count the resources required to develop and maintain C++ code with all its pointer foulups and memory leaks versus PHP which is relatively simple and straightforward to develop and runs in a very stable manner on either a LAMP or WAMP stack. Sure servers eat up a lot of energy. But so do programmer armies who have to commute or log in or fill out timesheets by the forest, all to chase memory leaks, buffer overflows and the like. Oh yeah, and lets not forget the number of EXTRA servers you're going to have to put online to make up for the ones that need rebooted every few hours because some high school script kiddie doesn't bother to sufficiently check for memory leaks that chew through the server like a teen athelete on steroids. Maintainability is a HUGE factor in overall cost in terms of both $$$ and other resources. Use C++ or Assembler or whatever low level, low resource hogging language on a FEW critical sections, written by l337 coders, and let the pock faced script kiddie army churn out the mountains of PHP, .Net, JavaScript, etc that is at least garbage collected in their own VMs.

    --
    Be More, Be Manly, The Manly Geek Ubergeek Extraordinaire Blogger: www.manlygeek.com/blog Podcaster: podcast.man
  178. A trolling weak argument - but, this isn't... apk by Anonymous Coward · · Score: 0

    "1. It is not a compact format

    2. It has to be read into memory often the file itself isnt searchable or indexed.

    3. No support for Unicode host names (its an ANSI text file, not UTF8)

    4. There is no way to control access for readers and writers its a text file not a database

    5. If I was a malware writer this is the first place Id look to change things. Oliver day mentions this in his article. So does Wikipedia. - http://foredecker.wordpress.com/2009/12/07/dear-anonymous-slashdot-guy/

    Per your points on HOSTS files, my disprovals of your points are below, 1 by 1, via an emumerated reply:

    ====

    "1. It is not a compact format" - by Foredecker http://foredecker.wordpress.com/2009/12/07/dear-anonymous-slashdot-guy/

    APK REPLY/REBUTTAL: It isn't when you folks removed what makes it smaller & F A S T E R to read up from disk/file, into memory (0 blocking address, no longer possible in VISTA, Windows Server 2008, & Windows 7 ever since MS Patch Tuesday 12/08/2008, when Microsoft REMOVED 0 as a legit blocking IP address in HOSTS files in those versions of Windows NT based OS).

    Funny - because Windows 2000 had it & still does (as do Windows XP & Windows Server 2003 still). However, Windows 2000 didn't have 0 as a LEGITIMATE BLOCKING ADDRESS FOR HOSTS FILES in its original model for sale on CD... 0 was added in a service pack, afterwards (because it is smaller & faster, & a good thing... a good thing I am wondering WHY you have removed from HOSTS in Windows VISTA onwards... when it DID WORK ON VISTA, up to 12/09/2008 MS Patch Tuesday, but not afterwards!)

    ----

    "2. It has to be read into memory often the file itself isnt searchable or indexed" - by Foredecker http://foredecker.wordpress.com/2009/12/07/dear-anonymous-slashdot-guy/

    APK REPLY/REBUTTAL: NO, it does not.

    The local DNS client can handle it, but ONLY UP TO A CERTAIN SIZE (another problem IS the DNS CLIENT CACHE ITSELF, failing on larger HOSTS files, mind you)... so, you disable the local DNS client service is all.

    Then, your local diskcache subsystem caches the file & "repeated reads" are ELIMINATED!

    ----

    "3. No support for Unicode host names (its an ANSI text file, not UTF8)" - by Foredecker http://foredecker.wordpress.com/2009/12/07/dear-anonymous-slashdot-guy/

    APK REPLY/REBUTTAL: The HOSTS file doesn't require this. Not on *NIX variants, not on Windows. It is a text file, period & SPECIFICALLY, an ASCII text file (not the types you stated), per RFC 606, 608, & 627 (nor is it a database as you seem to be alluding to above, this is how it was designed not by Microsoft, but by the folks in the *NIX world, period, via the BSD reference design which Microsoft uses for their IP stack).

    ----

    "4. There is no way to control access for readers and writers its a text file not a database" - by Foredecker http://foredecker.wordpress.com/2009/12/07/dear-anonymous-slashdot-guy/

    APK REPLY/REBUTTAL: You can READ ONLY (set this attribute on it) protect it. Easy enough (or more radically, apply ACL security to it)

    ----

    "5.) If I was a malware writer this is the first place Id look to change things. Oliver day mentions this in his article" - by Foredecker http://foredecker.wordpres

  179. Re:Scripting not programming by tomhudson · · Score: 1

    typically they're extremely cache and DB intensive if they're written right

    No. The less you have to hit the database, the better. Slashdot is a good example - people who are logged in are only 1/3 of all page views, but require 2/3 of the boxes.

    Also, caches like static content the best.

  180. Re:Scripting not programming by tolan-b · · Score: 1

    What? The point is that they should be dealing with relatively static data, therefore they go to their cache layer first (in this order usually: memory, memcached or similar, DB query cache, DB query)

    Of course the less you have to hit the DB the better, but even moreso the less you have to re-calculate things that don't change the better.