#Performance on API

4 messages · Page 1 of 1 (latest)

wooden summit
#

I'm currently working on a Laravel project where we would like to optimize our repsonse times.

I created a simple inline controller and tested a few things with clockwork. We thought it was db related. We ruled that one out. However I'm mostly surprised how much time is left in the internals of Laravel. Any tricks or advice on how to minimalize those. Or is it just Laravel nature?

I also checked this with the debugbar and most time is spend in the booting part.

Route::get('db-timing', function () {
    // Start timer for the first query
    $startFirstQuery = microtime(true);
    $firstQueryResult = DB::select('SELECT 1');
    $endFirstQuery = microtime(true);
    $firstQueryDuration = $endFirstQuery - $startFirstQuery;

    // Start timer for the second query
    $startSecondQuery = microtime(true);
    $secondQueryResult = DB::select('SELECT 1');
    $endSecondQuery = microtime(true);
    $secondQueryDuration = $endSecondQuery - $startSecondQuery;

    return response()->json([
        'first_query_duration' => $firstQueryDuration,
        'second_query_duration' => $secondQueryDuration,
    ]);
});
fervent shell
#

Well, the framework would need to boot every request, that's the nature of Laravel. Booting times can be influenced by a lot tho, like how you're running your app locally, or inefficient service providers (third party, or your own)

static anvil
#

0.4s is pretty high, even for boot. Some of that will be your middleware, some will be network and some of it is just the fact that you chose the worst possible language (PHP) for performance and paired it with a framework (laravel + ORM) that does lots of "magic" stuff with tons of hooks for events and ETL.

But from an influenceable angle, are you caching your config? events? views? routes?

If you're not caching routes or events, that can introduce a fair bit of boot time.

One of the things that used to cause me grief all the time was a slow DNS. If you have a slow DNS server, queries to the DNS server (like sending the query to the DB, if you're using a hostname instead of an IP) could cause massive delays. This could be made worse if you're booting other external services for data capture (like clockwork and debugbar).

When you disable those extra services, do times improve?

onyx torrent