S
S
svtl182019-09-18 21:27:32
PHP
svtl18, 2019-09-18 21:27:32

How to solve load problems, or how to calculate character. VPS?

Good afternoon.
I had an order for the development of one project.
Also in this project, I wrote an API for a mobile application.
API allows you to register users, authorize them, and get information about the user.
The project is very closely tied to CRM Rkeeper.
I will describe one process, the registration process.
The mobile application sends a request for user registration, the web server in turn:
1. Validates the data
2. Creates a row in the database (in the users table)
3. Sends an email to confirm email
4. Calls CRM via API - searches for the user by email
-- If yes, it synchronizes site data with CRM
-- If not, then creates this user in CRM and synchronizes the data.
5. Contacts CRM via API and creates a loyalty card

. All this is done synchronously and without queues.
The client did load testing and started complaining that everything was bad.
We started 50 threads at the same time and gave the following result in ms:
Registration:42512,4408
Registration:37837,6567
Registration:40158,8063
Registration:41586,602
Registration:43232,8989
-------------- -----------
Registration:43027,9108
Registration:31010,2805
Registration:37531,425
Registration:34658,028
Registration:59004,4044

I developed only the backend part on Laravel. I didn't do the deployment. I'm not DevOps and I don't understand anything about it.
The client chose a hoster - https://hostpro.ua/
VPS characteristics:
* CPU - 2 cores x 2.2 Ghz
* Memory - 2Gb
* HDD - 30 gb

They put nginx + mysql + php7.2 there

In general, they accuse me, and I don’t even know what answer them.
If I register myself, then the whole process takes 3-5 seconds.
I don't even know how to stress.

What do you think ? Where can there be problems? Maybe a weak or bad VPS? Or maybe the web server is poorly configured?
Obviously, there are a lot of requests in CRM, which for good would be thrown into the queue. But this cannot be done, because in response to the registration request, the application must already receive a loyalty card number.

I will be glad to any advice.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
Lazy @BojackHorseman PHP, 2019-09-18
Tag

yes in profiling everything will be visible. fasten xhprof, run 50 threads again and see what's stupid. why guess when there is a great tool. here is an example
5d827a5d93d13949819938.png

S
Sanes, 2019-09-18
@Sanes

VDS needs to be tested. What is written in the tariff may differ in reality at times.

M
m0zart89, 2019-09-18
@m0zart89

You can do a simple trace using xdebug.
At the beginning of the script, we add, right at the beginning of the Laravel index.php in the public folder (make a copy of index.php for peace of mind):

<?php

if (!file_exists(dirname(__DIR__)."/xdebug")) {
    mkdir(dirname(__DIR__)."/xdebug");
}
xdebug_start_trace(dirname(__DIR__)."/xdebug/".rand(1,10000));

We pass a random number so that when the stress test is turned on, each time it is accessed, its own trace file is created, a crutch, but not the essence.
Next, we get files in the Laravel root folder in the xdebug folder, which look like:
...
0.4393   81359120       -> drupal_alter() /Users/mike/projects/unicorns/includes/menu.inc:508
0.4395   81359264         -> is_array() /Users/mike/projects/unicorns/includes/module.inc:1000
0.4398   81359624         -> module_implements() /Users/mike/projects/unicorns/includes/module.inc:1021
...

The first column is the time counter for the execution of the called function, i.e. for example, in the middle, the execution of the is_array () function took 0.003 seconds, for example.
We analyze the trace and identify the bottleneck.
Possible options:
1) Slows down the API server, it is necessary to optimize the nginx + php bundle (unlikely).
2) Slows down the CRM API that your API accesses (more likely, there may be connection restrictions, etc.).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question