Answer the question
In order to leave comments, you need to log in
Due to the large number of visitors, the site floated, what should I do?
Hello everyone, please tell me what to do?
Description
I made a site, as usual on Html, Css, Jquery, Ajax , Php.
I started testing it, 10 people went to the site at once and started incredibly quickly clicking on everything in a row at the same time, in 1 minute about 1500 requests were received in the database and the same number of answers, and the whole site swam , everything stopped being displayed, it generally hung up to be added.
It should be borne in mind that the site always interacts with the database, you need to constantly record and display something.
Questions:
How to fix the problem other than refactoring to Nodejs?
Are there solutions other than Nodejs?
How to get millions of people to visit your siteand that the site can withstand the load.
Thank you very much in advance.
Answer the question
In order to leave comments, you need to log in
How to fix the problem other than refactoring to Nodejs?
Profile, log slow queries, look for bottlenecks. 1500 requests is nothing. I currently have a parser enabled, which makes 1000 requests per second to the database and it is normal.
PS vk.com is written in PHP and it's fine too.
Well, actually 1500 requests per minute is still not enough. Such a "load" is kept by a standard web server (Apache + PHP) on a virtual machine with 512MB of RAM and 1 core. So, in my opinion, something is wrong in your code. What is the actual site? What PHP engine?
Plus, you're building the question incorrectly. What does it mean in your understanding of "an incredible number of people"? For what purpose? Is your site a social network? Internet shop?
And what about caching MySQL queries, data? Are you sure you don't use it?
I bet that you don’t have indexes in the database, so queries go slowly, so everything takes a long time and falls
Use memcache or redis so that you don't have to go to the database for the same data every time - should significantly increase performance.
For sites with millions of visitors, powerful servers or several servers are used - vertical or horizontal scaling, as a rule, horizontal scaling is used plus the same redis, memcache, elastic search, etc.
Memcache and redis are such programs (services) that work in the background and allow you to save data in RAM in the key: value format. for example
123: "Здесь какой то длинный текст полученный из БД"
. Access to this data is faster than to the database, because. the data is in RAM, but in order for it to get there, you need to write it there from the database and then you can use it. redis has richer features, but you can start with memcache. Memcache also has very great possibilities - you can read books on this topic. <?php
$m = new Memcached();
$m->addServer('localhost', 11211);
if (!($text = $m->get('my_text'))) { // Проверяем есть ли значение в кэше и если нет то идем в базу
if ($m->getResultCode() == Memcached::RES_NOTFOUND) {
$text = Get_Data_From_DB(); // Получение каких нибудь данных из БД
$m->set('my_text', $text); // Установка значения в кэше
} else {
/* log error */
/* ... */
}
}
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question