tags:

views:

263

answers:

7

it seems that most of the time, the speed gained is not worth it -- is it so? otherwise many people will do it for their most popular page. Is there real benefit of using a C program. I can think of a case where it is not important: when the network bottleneck on the server is quite bigger than the CPU bottleneck, then how fast the program runs becomes less important.

A: 

Most websites use caching in memory for high speed response. In this case the load is not in the creation of the page anymore so I wouldn't go for c program.

Nir
is it true that even with caching in memory, the C program is still going to run at least a few times faster?
動靜能量
when a memory cache is involved 1000s of page views can be created with one run of the code that actually creates them so the speed of creation of the page is no longer a bottleneck
Nir
oh that's with static page, isn't it? what if it is dynamic?
動靜能量
With dynamic pages usually its possible to cache database queries that repeat themselves (like the count of questions on OS). As for unique data that is shown to a small number of people (like this comment), the bottleneck is usually the database access and not the php part. so still C won't help much.The real bottoleneck is in the database and not in the code itself. In which case all common data.
Nir
A: 

I would say, even in the case that you illustrated, it would never be worth it to redesign your server side work to run as a C program. Regardless of the amount of traffic.

The cost of upgrading your server or implementing effective caching will always be less than the work it would require to write rewrite your server side code to run in C.

Robert Venables
never say never, yahoo shopping have core code written in C for speed.It all comes down to the relative cost of development vs servers, at a certain (incredibly high) point, a couple of months of dev time is cheaper than extra servers or a whole new architecture.
garrow
Very interesting! Thank you.
Robert Venables
+7  A: 

C is an excellent language. But it was designed for systems level programming not making web pages. PHP on the other hand was designed for making web pages. Use the right tool for the right job. In this case PHP.

Also you're starting with a faulty premise. Namely that PHP won't be fast enough to deliver the page content. There are a multitude of websites out there that simply disagree with that statement. Maybe there is some corner case out there that C is the only choice for the job but I find it highly unlikely that you are going to run into that scenario.

JaredPar
-1 because ....
JaredPar
Unlike lower-level languages like Assembly, C is a general-purpose language. That's why Apache is written in C, as well as so many other Web applications. The "right tool for the right job" could be: if you're comfortable with C, and speed is important, then use it.
Tony
I wouldn't use C because the handling of strings etc. is quite error prone and tedious, but it's possible.
tstenner
@Tony, You're making a big assumption by saying the speed of the language is a limiting factor. My guess is network bandwidth, database and general IO are much more of limiting factors than the language. Also your comparison with Apache is a false analogy. Apache is a web server, we're talking about web applications.
JaredPar
@JaredPar: Apache is a Web application, in addition to being a server. That's why it was possible to write it in C. But now we're splitting hairs.Network bandwidth and the other factors you mentioned may be more limiting, but using a compiled language instead of PHP might show a noticeable improvement. It's possible that CPU resources are more limited than the network resources, as Jian Lin mentioned. In any case, I think C would be worth a try.
Tony
A: 

it really depends on the code. For instance, I'd rather compile C code that deals with my network graph algorithm; however, i'd never convert a simple static page that displays minimal CSS.

dassouki
+2  A: 

When you use C as a hammer, everything looks like a thumb.

As Jared stated above, use the right tools. You could do it all in C, many have. But the development speed of PHP vs C for the web is something you might look into also. Something that is pretty simple to do in PHP (dynamic array's for example) is something that is not simple in C.

Ólafur Waage
+1, I love the insertion of thumb for nail.
JaredPar
Not my quote though, but it fits in this contex
Ólafur Waage
A: 

If you even need to ask the question, the answer is no.

Web based apps are limited by network, database, i/o, and CPU, in that order, and the speed increase you would get by writing your code in C would certainly be offset but the increased development time, due the nature of the language, and still be affected more markedly by those other factors.

If your code needs to run really fast, doing something quite computationally difficult or involved, perhaps C could be the right answer, but most web sites are not like this.

It could be worthwhile having very specific processing or heavy lifting code rewritten as C modules once it is determined that the current implementation is too slow, but these optimisations are best done down the track, with sure knowledge of the real bottlenecks in the app.

If you have a decent library or platform eg .NET MVC, using C# for general web dev is a feasible idea. C, not so much.

garrow
A: 

There is one scenario (and in all other cases I can think of, the answer is that it won't worth it -good reasonings are in the other answers).

So the case is when

  • the program needs to do a lot of data processing or calculations
  • there are heavily optimized C codes available

I'd say a complex raytracing system is a candidate for the situation, but nothing under the complexity of this.

Even in this case, I'd implement the pages in PHP and run a background job to do the heavy lifting.

Csaba Kétszeri