📜 ⬆️ ⬇️

About kPHP: how kittens speed up VKontakte

Hi, habrovchane. Many already had time to read about kPHP from VKontakte in the past , and somewhere else, but of course there were few details. To satisfy our own curiosity and interest from the community, we turned for comments to the original source, that is, Pavel Durov, who recommended me to talk about kPHP with the guys from the team - Oleg Illarionov and Vasily Babich, who were responsible for transferring the VC to the latest development.

First of all, I asked those questions that sounded in the comments to the announcement: what's with the PLO, who is faster - an elephant or whale Java C # Go or kPHP, in which projects the kPHP will be most useful, and so on. In addition, we talked about development plans and, a little, about other developments and the “code” VK kitchen.

Oleg, Vasily, hello. So what is kPHP? What is its essence?

Oleg Illarionov:
')
Hello! kPHP - PHP translator in C ++, which, among other things, analyzes the code, displays the types of variables, and where it could not be unambiguously derived - uses universal variables in which data of any type can be stored.
Of course, kPHP is not a thing that will compile any PHP code and it will work - in fact, kphp is a very good static code analyzer that finds errors, both potential and actual. By the way, when translating the site (we are talking about VKontakte), even a few small innovations were launched that were made a long time ago, but because of bugs in the code they were not available to the general public.

Many questions are related both to the support of the basic PHP methods and to the OOP. In addition to the already voiced - both about the standard and limited support for the PLO, can you add something?

OI:
In kPHP There is a huge mass of everything, even things that we ( VKontakte ) do not use, but so far there are not some very serious pieces - for example, a DOMDocument.
As for OOP, it is currently not supported in kPHP, with the exception of a few standard PHP objects. One of the tasks when translating a site to kPHP was to completely get rid of OOP. But this absence was made more like a feature, speed was the main vector in the development of kPHP, It plays not in favor of supporting OOP and, moreover, OOP is good in the first place when you have a hundred developers on the project or there is an abundance of interfaces in it.

The classic question in the comments was: "Is kPHP faster than Java C # Go?"

OI:
Depends on what exactly to test and how to write the code. With kPHP it is very interesting: for example, the speed depends on how it displays the type of individual variables. In general, kPHP was planned as incompatible with PHP language, there are a number of constructs that, for example, allow you to explicitly set the types of variables to speed up execution. But due to the fact that we have a lot of code (the compiled binary weighs about 300 megabytes), the compilation takes not a few seconds as planned, and the minutes - despite the fact that kPHP recompiles only the changed part of the code - you have to develop features on regular PHP , and it still does not allow us to use all the advantages.

Vasily Babich:
Comparison with Java C # Go is difficult - the speed of kPHP, as Oleg has already noted, is very dependent on the code that they compile - if it's good, then the speed is much higher than that of Java / C # - in fact, this is pure C ++. But if the code is not very good, then it works more slowly. Probably, if you try hard, you can come up with a synthetic example, where the code is similar, but kPHP is slower - but we didn’t ask ourselves for this purpose :)

We have already seen beautiful graphics accelerating the loading of the main pages of VKontakte due to the transition to kPHP. What other benefits can kPHP bring?

OI:
A significant advantage in the use of memory.

WB:
Yes, with kPHP significantly less CPU and RAM usage. As far as I know, we began to use almost two times fewer servers for processing requests, despite the fact that they are not only doing this - some other systems sometimes work on them, like memcache. Of course, kPHP is primarily intended for highload projects, which is not surprising, given the tasks for which we are developing it.

Some habrovchane critically reacted to the double speed increase VKontakte, indicating that the acceleration of 10 times would be, of course, a much more impressive result. So, 2 times in total?

OI:
It should be understood that the fact that the site is accelerated by 2 times does not mean that kPHP is twice as fast as PHP, this is not so. The fact is that in addition to executing the code, a very substantial part of the time is spent on accessing databases, engines, and so on. I think the code execution itself has accelerated more than 10 times.
And also about speed: a web server is built into kPHP, that is, in combination with it, Apache is not needed.

WB:
Yes, most of the time the page is generated now is not the execution of the PHP code, but the waiting for a response to requests for data (to other servers). Of course, we try to use this waiting time somehow, but it really turns out that there are still a lot of expectations, its kPHP does not speed up. As Oleg said, the actual growth rate is much higher.

Oleg, you mentioned the bases and in this regard, the question about them: do you use your own work or something standardly doped?

OI:
Now we practically do not use MySQL, except perhaps only where there is a small load and have not yet reached out to transfer our hands to our own engines. Where data is stored a lot they have been used for a long time. There are a huge number of them written, it is now difficult to imagine a task that cannot be solved without MySQL.
In general, a number of our standard functions, which we have prudently brought into a separate library, are implemented in C ++.
However, we used this solution even before kPHP - as you know, new functions written in C can also be added to PHP.

Are there plans to accelerate or (suddenly!) Reveal engines to the public ?

WB:
Those written by our guys (instead of MySQL) and working on the memcache protocol are already quite strongly accelerated. However, this protocol does not allow speeding up everything as much as we could. Therefore, we gradually move away from the memcache protocol to our own, which is similar to mtproto, described in the contest for Android - but for the server side (for communication between the servers that respond to the request and servers with data).
About the opening of the public - yes, we planned to open engines on the memcache protocol, but so far we have not reached our hands.

Returning to kPHP, what are your plans for its development and support? Will you cut or give away to the community?

OI:
From the nearest - the guys are planning to add OOP, since if we want to embed mtproto, the developers will need it.

Thank! And finally, the most important question: what is k?

WB:
K is a prefix from the word kitten, which has already become a tradition in the development of our guys :)




We got this kPHP interview, Habr, thank you for reading this wall of the text without a single picture. To smooth this awkwardness, I add a little prefix to the topic:

image

And, of course, if there are questions on the topic, Roem.ru would be happy to ask the guys about other details of interest to the community.

Source: https://habr.com/ru/post/187352/


All Articles