S
S
Suleimanov_Ismar2015-11-30 15:10:18
PHP
Suleimanov_Ismar, 2015-11-30 15:10:18

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

7 answer(s)
V
Vitaly Khomenko, 2015-11-30
@Suleimanov_Ismar

How to fix the problem other than refactoring to Nodejs?

Control queries to the database. Do not create repeated identical requests unnecessarily. Reuse the received data. Use data caching. Optimize the database structure, including indexes.
The problem is not with PHP.
Use the recommendations that I and others have written to you.
Truth of life: I read the book "How to learn PHP in 20 minutes" - I made a website. Everything is cool, but if more than 3 people visit, the site stops working! PHP - ha**! Leaving NodeJS\Ruby\Python\*...

E
Eugene, 2015-11-30
@Nc_Soft

Rewrite to the node, it will fall even faster: D

R
Roman Kitaev, 2015-11-30
@deliro

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.

A
Anton, 2015-11-30
@karminski

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?

R
Robot, 2015-11-30
@iam_not_a_robot

I bet that you don’t have indexes in the database, so queries go slowly, so everything takes a long time and falls

A
asd111, 2015-11-30
@asd111

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.
Here is the manual for php.
php.net/manual/ru/book.memcached.php
Working with the cache looks something like this:
<?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 */
        /* ...       */
    }
}
?>

A
Andrey, 2015-12-14
@andreyvlru

1500 / 10 / 60 = 2.5 requests per second is very little localize the
problem

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question