Will web development in C ++ cgi really have huge performance?

I ask a question after reading this article http://stevehanov.ca/blog/index.php?id=95

Also, is it worth using cgi instead of fastcgi?

Update: why do some people pretend as if in response to “that you get a performance improvement of 20-30%”? Is this a pure guess or is this number based on a solid test? I saw that the performance of HipHop is 10 times greater.

+7
source share
6 answers

I made webdev in several languages ​​and frameworks, including python, php and perl. I accept them myself, and my largest sites receive about 20 thousand hits per day.

Any language and framework that has a reasonable speed can be increased to 20 thousand hits per day, just throwing resources on it. Some take more resources than others. (Plone, Joomla. I look at you).

My witty sites (not yet made) take up a lot more (from memory by about 5000%), knocking (using seige) than, for example, my python sites. I.e. When I hit them as hard as I can with seige, witty sites serve a lot more pages per second.

I know this is not a real general test.

Other speed advantages that wittily give you:

Multithreading

If you deploy with a built-in websrever (for example, behind a ha-proxy) and your application is multithreaded, it will load a lot less memory than saying a perl or php application.

Typically, with php and perl applications, you will run Apache for each incoming connection, and each process loads the entire PHP interpreter, all the code, variables and objects, and what not. With heavy frameworks such as Joomla and Wordpress (depending on the number of plugins), each process can receive supernatural memory consumption.

In a Wt application, each session loads a WApplication instance (C ++ object) and the entire widget tree and more. But the memory that the code uses remains unchanged, no matter how many connections.

Embedded Web2.0 ness

Typically, with traditional applications, they are still built around the old "HTTP request". "We serve the page" .. "done" style of things. I know that they add more and more AJAXy ticks all the time.

With Wt, it by default uses WebSockets, where possible, only to refresh the part of the page that needs updating. It returns to standard AJAX, and then if it does not support HTTP requests. With clients that support AJAX and WebSockets, the same WApplication C ++ object is constantly used. Therefore, when setting up a new session and speed, the speed is not lost.

In response to "C ++ is too complicated for webdev"

C ++ has a bit of a learning curve. In the mid-nineties, we made websites in Java j2ee. It was considered commercially viable at the time, and it was a great frightening pain to develop, but it had a good advantage in promoting good documentation and coding techniques.

Scripting websites make it easy to use shortcuts and not realize that they are there. For example, one 8-year-old perl site I was working on had some code duplicated and no one noticed. Each time he showed a list of products, he ran the same SQL query twice.

With a C ++ site, I think it would have less chance because the Perl site did not have such a programming structure (as functions), it was just perl and built-in html. In C ++, you are likely to have methods with names, and ultimately with name collisions.

Types

Once there was a method that accepted the identifier int, later we changed it to the string uuid. The Python code was great, we didn’t think we needed to change it; he went perfectly. However, there was a small line deep in the depths, which had a different effect when you passed the line to it. It is very difficult to track down the error by messing up the database. (Fortunately only on dev and test machines).

C ++ would probably complain a lot and make us rewrite the functions involved, rather than being lazy buggers.

With C ++ and Java, compiler errors and warns of many such errors for you.

I believe that unit testing is usually not so necessary with C ++ applications (don't shoot at me), compared to applications in the scripting language. This is because the language provides many things that you usually add to the unit test for a python application.

Summary

From my experience so far .. Wt takes more time to develop material than existing frameworks .. mainly because existing frameworks have much more features. However, it is easier to make extremely customized applications in Wt than Wordpress imho.

+19
source

From the people with whom I spoke, who switched from PHP to Wt (C ++ web infrastructure), he reported significant improvements. From the small applications that I created using Wt to ​​find out about this, I saw that it works faster than the same applications like PHP that I created. Take the information for whatever you want, but I am for sale.

+9
source

This reminds me of how 20-30 years ago, people built Assembly against C, and then 10-20 years ago C against C ++. Of course, C ++ will be faster than PHP / Rails, but it will take 5 times the effort to create a supported and scalable application.

The fact is that you get a productivity improvement of 20-30%, sacrificing your development resources. Would you prefer that you work 30% faster or have 1/2 of the functions implemented?

+5
source

Most web applications are network bound instead of processor bound. Writing your application in C ++ instead of a higher level language does not make much sense if you are not performing really heavy calculations. In addition, writing the correct C ++ programs is difficult. It will take more time to write the application, and it is more likely that the program will fail for spectacular purposes due to incorrect pointers, memory errors, undefined behavior, etc. In general, I would say that it is not worth it.

+3
source

Whenever you remove the OS interpretation or abstraction layer, you are sure to get some performance boost. However, the language or technology itself does not automatically mean that all your problems have been resolved. I fixed the C ++ code, which took many hours to process a relatively simple set of records. The problem was implementation, and the fix was not related to language features or restrictions.

Assuming everything is implemented correctly, you will definitely get better performance. The problem will be in detecting errors. One of the problems with C ++ is that many developers are currently "trained" or used to having many details related to managing memory for objects. This eliminates the need to consider things like "What can happen if I pass this pointer to multiple threads?" Sometimes this works well, but not always. You still have some subtleties of the language that you need to consider regardless of how objects hide unpleasant details.

In my experience, you will need some experienced C ++ developers who will monitor the code so that it does not have enough errors and memory leaks.

+3
source

Of course, I am not for sale on this occasion. If you want to improve performance in PHP, why not use the Java framework (or even better Scala)? They are much better suited for web development, have good, relatively easy-to-use frameworks and avoid many C ++ headaches. I have always seen one of the main advantages of web development (and most modern uncharacteristic / high-performance applications) as the opportunity to avoid the headaches that arise with the development of C / C ++.

+3
source

All Articles