T
T
Tutucu2020-10-30 15:04:49
MySQL
Tutucu, 2020-10-30 15:04:49

Why does it sometimes take too long for a model to be added to the database (Laravel)?

Periodically, the following requests appear in the server logs:
5f9bfa96de2b1832548405.png
I.e. periodically, the server response speed starts to increase from 0.2 s to 3 or even 8 seconds. This happens randomly and does not depend on server load or time of day.
In the php-fpm slow request logs, these moments look like this:

[30-Oct-2020 09:13:46]  [pool www] pid 5494
script_filename = /public/index.php
[0x00007f53c441f0a0] execute() /vendor/laravel/framework/src/Illuminate/Database/Connection.php:459
[0x00007f53c441f010] Illuminate\Database\{closure}() /vendor/laravel/framework/src/Illuminate/Database/Connection.php:658
[0x00007f53c441ef50] runQueryCallback() /vendor/laravel/framework/src/Illuminate/Database/Connection.php:625
[0x00007f53c441ee90] run() /vendor/laravel/framework/src/Illuminate/Database/Connection.php:460
[0x00007f53c441ee10] statement() /vendor/laravel/framework/src/Illuminate/Database/Connection.php:412
[0x00007f53c441ed90] insert() /vendor/laravel/framework/src/Illuminate/Database/Query/Processors/Processor.php:32
[0x00007f53c441ece0] processInsertGetId() /vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2658
[0x00007f53c441ec30] insertGetId() /vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:1317
[0x00007f53c441eb60] __call() /vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:839
[0x00007f53c441eab0] insertAndSetId() /vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:804
[0x00007f53c441ea20] performInsert() /vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:667
[0x00007f53c441e970] save() /vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:749
[0x00007f53c441e910] Illuminate\Database\Eloquent\{closure}() /vendor/laravel/framework/src/Illuminate/Support/helpers.php:424
[0x00007f53c441e890] tap() /vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:750
[0x00007f53c441e810] create() /vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php:23
[0x00007f53c441e730] forwardCallTo() /vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1618
[0x00007f53c441e6a0] __call() /vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1630
[0x00007f53c441e610] __callStatic() /app/Models/SkillRequest.php:102
[0x00007f53c441e540] send() /app/Http/Controllers/Skills/GameSearchController.php:294
[0x00007f53c441e400] index() /vendor/laravel/framework/src/Illuminate/Routing/Controller.php:54


The part of the long script pointed to by the SkillRequest.php:102 log in GameSearchController.php:294 is just adding a model instance to the database by the Laravel base function:
SkillRequest::create($skill_request);
The model itself:
protected $fillable = [
    'skill_id',
    'user_id',
    'type',
    'request_content',
    'response_content',
  ];

  protected $casts = [
    'request_content' => 'array',
    'response_content' => 'array',
  ];

Migration structure:
Schema::create('skill_requests', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('skill_id', 255);
            $table->string('user_id', 255);
            $table->string('type')->default(NULL);
            $table->json('request_content')->default(NULL);
            $table->json('response_content')->default(NULL);
            $table->timestamps();
        });

The mysql slow query log is empty about this.
The purpose of this script is to keep logs, and the script starts up with every request, but in some cases it works well, and in others it doesn't :( What could be the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Shamanov, 2020-11-03
@SilenceOfWinter

because the code does not work in a spherical vacuum, but in parallel with other tasks

K
Konstantin, 2021-06-11
@derwin

Try disabling dns resolv
google for skip-name-resolve

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question