#StackBounty: #performance #raspbian #midi #lag #latency How to debug program latency?

Bounty: 100

I’m trying to run amsynth on a rpi. Latest version of raspbian, fresh install.

I tested amsynth on my x86 desktop and it works great, no latency.

On the rpi however, I get a delay of around 1 sec between sending a midi command (using vkeybd) and hearing the tone.

Setting a better niceness doesn’t seem to help.

I wrote a small script in python using the mido library to control amsynth also but I still hear the lag.

How would I go about trying to debug what is causing this? I am basically just an end user.

I’m guessing either the midi command is getting delayed somehow, or amsynth itself is lagging (seems unlikely).

Load average is 0.4 during these tests, vs 0.1 idling.

top shows amsynth hovering at 12% CPU utilization.

A low latency kernel shouldn’t be needed for this right? I would imagine that application would be for getting the latency down from 50 ms to 10 ms, for example, vs what I want to do here is just get the latency down from 1000 ms to 50 ms.


Get this bounty!!!

#StackBounty: #windows-10 #keyboard #performance #macbook-pro #boot-camp Windows 10 on Macbook Pro not responsive to keyboard input

Bounty: 150

I have a 2016 15-inch Macbook Pro, on which I installed Windows 10 via Boot Camp. But it’s often unresponsive to keyboard input, so I find myself slowing down for the OS. I don’t think this problem is limited to just one app. Rebooting into macOS makes it responsive.

I’ve rebooted the machine, applied all available updates via both Apple Software Update and Microsoft Store, but the problem still occurs.

Has anyone else encountered this? How do I debug and fix this, before I give up and delete the Windows partition?


Get this bounty!!!

#StackBounty: #performance #web-server #web-hosting #performance-monitoring #shared-hosting How to backtrace slowness of a shared hosti…

Bounty: 50

I have a shared hosting plan (godaddy), and time to time I suffer slowness problem. When this happens, I try to login to cpanel to double check if the problem is me or the server, and it also takes 1-2 minutes to enter cpanel.

As all customer service personal, they also lack of technical knowledge and always tries to persuade me the problem is on my side, and want me to remove browser cache.

I am telling them that this is a recurring problem, and I am trying to find a root cause, but they are not looking for a solution, and telling me everything seems fine on their side.

What can I do to backtrace this issue when I suffer this slowness so that when I call the customer service next time, I can show them some proving data, so they can actually work a little bit! .

P.S: There is no development on my website. Just updating the web shop products.


Get this bounty!!!

#StackBounty: #boot #18.04 #performance Slow boot in fresh install of Ubuntu 18.04

Bounty: 50

I recently did a fresh install of Ubuntu 18.04 on my brand new laptop ASUS ZenBook UX430UN and I am experiencing a very slow boot.

I am not sure how to debug and solve this issue. I came across several issues similar to mine with Ubuntu 18.04 but none of the workarounds improved my problem.

Symptoms:
After the system boot, I see the purple screen for a few seconds and then, the screen turns black and waits for cca 50 seconds before displaying the Ubuntu logo. After that, the system starts normally and works fine once booted.

I have a second desktop computer running the same system (both Ubuntu dists having the most recent updates) and it boots in under 10 seconds. This one is almost one minute, however.

Startup finished in 35.752s (kernel) + 12.683s (userspace) = 48.436s
graphical.target reached after 11.941s in userspace

I read that this issue might be related to low entropy during boot so I tried installing rng-tools and haveged but nothing changed.

This is the output of systemd-analyze blame:

7.027s NetworkManager-wait-online.service
      3.801s plymouth-start.service
      3.778s plymouth-read-write.service
      3.172s plymouth-quit-wait.service
      2.311s apt-daily-upgrade.service
      2.072s apparmor.service
       793ms snapd.service
       768ms fwupd.service
       726ms tlp.service
       544ms keyboard-setup.service
       412ms systemd-logind.service
       394ms dev-mapper-ubuntux2dx2dvgx2droot.device
       381ms snapd.seeded.service
       264ms snap-gnomex2d3x2d26x2d1604-59.mount
       252ms snap-gnomex2dcharacters-124.mount
       247ms snap-gnomex2dcalculator-238.mount
       214ms snap-core-5145.mount
       207ms NetworkManager.service
       200ms snap-gnomex2dcalculator-180.mount
       199ms snap-core-4486.mount
       198ms networkd-dispatcher.service
       186ms snap-gtkx2dcommonx2dthemes-701.mount
       184ms systemd-timesyncd.service

and systemd-analyze critical-chain:

The time after the unit is active or started is printed after the “@” character.
The time the unit takes to start is printed after the “+” character.

graphical.target @11.941s
└─multi-user.target @11.941s
  └─kerneloops.service @11.926s +14ms
    └─network-online.target @11.925s
      └─NetworkManager-wait-online.service @4.897s +7.027s
        └─NetworkManager.service @4.688s +207ms
          └─dbus.service @4.638s
            └─basic.target @4.619s
              └─sockets.target @4.619s
                └─snapd.socket @4.618s +838us
                  └─sysinit.target @4.616s
                    └─cryptsetup.target @4.611s
                      └─systemd-ask-password-wall.path @217ms
                        └─-.mount @215ms
                          └─system.slice @217ms
                            └─-.slice @215ms

I am not even sure how to debug this properly so I will be happy for any suggestions what to try. I am happy to provide more details if needed.


Get this bounty!!!

#StackBounty: #c++ #performance #algorithm #matrix #mathematics Determinant using Gauss Elimination

Bounty: 50

We had a question in examination to compute determinant of general square matrix.
Now I had made the normal program using Laplace Formula of determinant, ie, recursive solution.

Now I was thinking of reducing it into Upper Triangle Matrix and then the product of diagonal elements gives the determinant.

The code is following.

#include <iostream>
using namespace std;

const int N = 5;
int main()
{
    double array[N][N], det = 1;

    // initialise
    cout << "Enter " << N << "*" << N << " matrix:n";
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            cin >> array[i][j];
        }
    }

    for (int i = 0; i < N; ++i) 
    {
        bool flag = false; // flag := are all entries below a[i][i] including it zero?
        if (array[i][i] == 0) // If a[i][i] is zero then check rows below and swap
        {
            flag = true;
            for (int j = i; j < N; ++j)
            {
                if (array[j][i] != 0) {
                    det *= -1;
                    for (int k = 0; k < N; ++k) { 
                        double t = array[i][k]; // swapping
                        array[i][k] = array[j][k];
                        array[j][k] = t;
                        flag = false;
                    }
                }
            }
        }

        if (flag == true) {
            det = 0;
            break;
        }

        else {

            for (int j = i+1; j < N; ++j)
            {
                double store = array[j][i];
                for (int k = i; k < N; ++k) {
                    array[j][k] -= (array[i][k]*store)/array[i][i];

                } 
            }
            det *= array[i][i];
        }
    }

    cout << "Determinant: " << det;
    return 0;
}

The problems with this approach is that matrix needs to be of floating point datatypes. Worse, it gives wrong result for least significant place (ones digit) for all integral entries if I use datatype of entries as float. To overcome that, we can use double.

But still I :

  • need tips on improving performance of this method
  • need to know whether this method is better than Simple Laplace Formula?


Get this bounty!!!

#StackBounty: #python #performance #computational-geometry #memory-optimization #pytorch Intersection over Union for rotated rectangles

Bounty: 500

Problem Statement

I am trying to find the intersection over union (IoU) metric for one to several rotated rectangles compared to many different rotated rectangles. Here are some images to help visualize this metric:


The second metric is quite close to the scenario I’m trying to calculate, the white area divided by the combined black and white area.

Example

For each small box on the right we need to determine the IoU metric for each red box on the right. The output in this case will be an array of size (5, 756) since there are 5 boxes on the left with 756 IoU metrics for each box on the right.


My solution

To solve this problem, I fill in each “anchor” box (from the above right picture) individually and store that in an array. This is a binary array.

filled in anchor box

I then take these filled in anchor boxs (now separated so each box is in their own image as above) and find the IoU metric by simple multiplication and summation. This approach will calculate the IoU metric regardless of the shape of the objects passed in. However, it is extremely inefficient both in memory and computationally. I am using the pytorch library to load the arrays onto my GPU to parallelize the computations.

Code

This code runs in .

import numpy as np
import torch
import cv2
from timeit import Timer

def jaccard(box_a, box_b):
    denorm_bbox = torch.cat([box_a[:, :4]*768, box_a[:, 4].unsqueeze(1)*90], dim=1)
    b_boxes = list(map(lambda x:np.ceil(cv2.boxPoints(((x[1], x[0]), (x[2], x[3]), x[4]))), denorm_bbox.numpy()))
    b_imgs = torch.from_numpy(np.array([cv2.fillConvexPoly(np.zeros((768,768), dtype=np.uint8), np.int0(b), 1) for b in b_boxes]).astype(float)).float()
    intersection = torch.FloatTensor()
    summation = torch.FloatTensor()
    for b_img in b_imgs:
        intersection = torch.cat([intersection, (b_img*box_b).sum((1,2)).unsqueeze(0)])
        summation = torch.cat([summation, (b_img+box_b).sum((1,2)).unsqueeze(0)])
    return intersection / (summation - intersection + 1.0)


def main():
    anc_grids = [3,6,12]
    anc_zooms = [0.7]
    anc_ratios = [(1.,1)]
    anc_angles = np.array(range(-90, 90, 45))/90
    anchor_scales = [(anz*i,anz*j) for anz in anc_zooms for (i,j) in anc_ratios]
    k = len(anchor_scales) * len(anc_angles) # number of anchor boxes per anchor point
    anc_offsets = [1/(o*2) for o in anc_grids]

    anc_x = np.concatenate([np.repeat(np.linspace(ao, 1-ao, ag), ag) for ao,ag in zip(anc_offsets,anc_grids)])
    anc_y = np.concatenate([np.tile(np.linspace(ao, 1-ao, ag), ag) for ao,ag in zip(anc_offsets,anc_grids)])
    anc_ctrs = np.repeat(np.stack([anc_x,anc_y], axis=1), k, axis=0)
    anc_sizes = np.tile(np.concatenate([np.array([[o/ag,p/ag] for i in range(ag*ag) for o,p in anchor_scales])
                for ag in anc_grids]), (len(anc_angles),1))
    grid_sizes = torch.from_numpy(np.concatenate([np.array([ 1/ag       for i in range(ag*ag) for o,p in anchor_scales])
                   for ag in anc_grids for aa in anc_angles])).unsqueeze(1)
    anc_rots = np.tile(np.repeat(anc_angles, len(anchor_scales)), sum(i*i for i in anc_grids))[:,np.newaxis]
    anchors = torch.from_numpy(np.concatenate([anc_ctrs, anc_sizes, anc_rots], axis=1)).float()

    denorm_anchors = torch.cat([anchors[:, :4]*768, anchors[:, 4].unsqueeze(1)*90], dim=1)
    np_anchors = denorm_anchors.numpy()
    iou_anchors = list(map(lambda x:np.ceil(cv2.boxPoints(((x[1], x[0]), (x[2], x[3]), x[4]))), np_anchors))
    anchor_imgs = torch.from_numpy(np.array([cv2.fillConvexPoly(np.zeros((768,768), dtype=np.uint8), np.int0(a), 1) for a in iou_anchors]).astype(float)).float()

    test_tensor = torch.Tensor([[ 0.0807,  0.2844,  0.0174,  0.0117, -0.8440],
                                [ 0.3276,  0.0358,  0.0169,  0.0212, -0.1257],
                                [ 0.3040,  0.2904,  0.0101,  0.0157, -0.5000],
                                [ 0.0065,  0.2109,  0.0130,  0.0078, -1.0000],
                                [ 0.1895,  0.1556,  0.0143,  0.0091, -1.0000]])

    t = Timer(lambda: jaccard(test_tensor, anchor_imgs))
    print(f'Consuming {(len(anchors) * np.dtype(float).itemsize * 768 * 768)/1000000000} Gb on {"GPU" if anchors.is_cuda else "RAM"}')
    print(f'Averaging {t.timeit(number=100)/100} seconds per function call')
    print(jaccard(test_tensor, anchor_imgs))

if __name__ == '__main__':
    main()

Sample Run:

Consuming 3.567255552 Gb on RAM
Averaging 3.107201199789997 seconds per function call
tensor([[0.0020, 0.0000, 0.0020,  ..., 0.0000, 0.0000, 0.0000],
        [0.0000, 0.0000, 0.0000,  ..., 0.0000, 0.0000, 0.0000],
        [0.0000, 0.0000, 0.0000,  ..., 0.0000, 0.0000, 0.0000],
        [0.0000, 0.0000, 0.0000,  ..., 0.0000, 0.0000, 0.0000],
        [0.0026, 0.0026, 0.0026,  ..., 0.0000, 0.0000, 0.0000]])

The results of this run were on a i7-8700K for reference.


What I would like reviewed:

  • Memory Consumption: Right now I am consuming a lot of memory for all the anchor boxes I compare each box to. What are some ways I can dramatically reduce this without giving up the accuracy of my results?

  • Speed: I need this to run fast!


Get this bounty!!!

#StackBounty: #performance #sql #recursion #sql-server #t-sql Modeling tabular structure in MSSQL to store data like Excel sheet applyi…

Bounty: 50

I’ve created this database structure to store tabular information (it’s a simplification of my real structure but enough to show the point). In it I have Sheets and each Sheet can define different Columns. The important part is that with this structure I can define different datatypes for each Column.

Those could be divided in two groups: Natives (defined in the Native_Types table) and SheetType from the already created Sheets.

Model structure

Code to get unpivoted data:

CREATE VIEW RowsData
AS
    SELECT r.ID, s.ID SheetID, col.ID ColID, 
            col.Name, ISNULL(clsVal.NativeValue, cls.NativeValue) NativeValue
    FROM Sheets s
        INNER JOIN [Columns] col ON s.ID = col.SheetID
        INNER JOIN [Rows] r ON s.ID = r.SheetID
        INNER JOIN Cells cls ON r.ID = cls.RowID AND col.ID = cls.ColumnID
        LEFT OUTER JOIN [Rows] rType ON cls.RowValueID = rType.ID
        LEFT OUTER JOIN Sheets sType ON rType.SheetID = sType.ID
        LEFT OUTER JOIN Cells clsVal ON rType.ID = clsVal.RowID AND sType.WhenIsTypeShowThisColumnIDValue = clsVal.ColumnID
GO

Sample data:

ID          SheetID     ColID       Name               NativeValue
----------- ----------- ----------- ------------------ ------------
1           1           1           Person Name        Aron
1           1           2           Person Country     Uruguay
2           1           1           Person Name        Sam
3           2           4           Country Name       Uruguay
4           2           4           Country Name       USA
5           2           4           Country Name       Russia
6           3           5           Pet Name           Mickey
6           3           6           Pet Age            83
6           3           7           Pet Person Owner   Aron
7           3           5           Pet Name           Pluto
7           3           6           Pet Age            8
7           3           7           Pet Person Owner   Aron
8           3           5           Pet Name           Zabivaka
8           3           6           Pet Age            4
8           3           7           Pet Person Owner   Sam

From here is all ok and any suggestion if there is a better way or any
improvements are welcome!


Weird stuff begins

Then I’ve implemented some kind of inheritance over Columns and its Cells.
For instance defining new Column for Sheet 3 (Pets) called “Pet Country” (setting it SheetTypeID -> 2, Countries). Now Pets have a Column “Pet Country” but instead of define a Cell value for each one if I define this Column as inherited (and particular structure to support in which way) I could inherit the Country value from “Pet Owner”. Remember that “Pet Owner” is of SheetTypeID 1 (Persons) and this Sheet have a Column of SheetTypeID 2 (Countries).

By simplifying I mean that if I have a Pet that has a Column “Pet Owner” and “Pet Country,” I don’t want to specify manually the “Pet Country” value, I want to inherit it from “Pet Owner” related with each Pet.

To accomplish that I have added two auxiliary fields to Columns table:

  • ColumnSameSheetInheritFromID -> This defines from which Column of the same Sheet this Column must inherit (must be Sheet type Column).

  • ColumnRelatedToFromColumnTypeID -> This defines from which Column of the Sheet type of the above Column must this Campo get the real inherited Cell value then.

Adjusted diagram:

Adjusted diagram


Helper self referenced function to get inherited Cells from Columns
(here is where I presume should be a better way to do things)

CREATE FUNCTION [dbo].[GetInheritedCells](@rowID INT, @colID INT)
RETURNS @result TABLE (ID INT)
AS
BEGIN   

    DECLARE @ColumnSameSheetInheritFromID INT = NULL;
    DECLARE @ColumnRelatedToFromColumnTypeID INT = NULL;

    --GETTING COLUMN FROM AND COLUMN VALUE IDs
    SELECT @ColumnSameSheetInheritFromID = col.ColumnSameSheetInheritFromID,
           @ColumnRelatedToFromColumnTypeID = col.ColumnRelatedToFromColumnTypeID  
    FROM dbo.[Columns] col
    WHERE col.ID = @colID;

    --IF COLUMN IS NOT INHERITED FUNCTION ENDS
    IF @ColumnSameSheetInheritFromID IS NULL OR @ColumnRelatedToFromColumnTypeID IS NULL
    BEGIN
        RETURN;
    END

    DECLARE @cellFromID INT = NULL;
    DECLARE @cellInhValueID INT = NULL;
    DECLARE @colFromAUX_ID INT = NULL;

    DECLARE @cellHaveValue INT = NULL;

    --GETTING REF FROM ROW RELATED TO THE RESPECTIVE DATA OF INHERITED COLUMN FROM AND CURRENT ROW              
    SELECT @cellFromID = cls.ID, 
           @colFromAUX_ID = col.ColumnSameSheetInheritFromID,
           @cellHaveValue = IIF(cls.RowValueID IS NULL, 0, 1)

        FROM dbo.[Rows] r
            LEFT OUTER JOIN dbo.[Columns] col
                ON r.SheetID = col.SheetID
            LEFT OUTER JOIN dbo.[Cells] cls
                ON r.ID = cls.RowID AND col.ID = cls.ColumnID
    WHERE r.ID = @rowID AND col.ID = @ColumnSameSheetInheritFromID

    IF @cellHaveValue = 0 AND @colFromAUX_ID IS NOT NULL
        SET @cellFromID = (SELECT TOP 1 ID FROM dbo.GetInheritedCells(@rowID, @ColumnSameSheetInheritFromID));
    ELSE IF @cellFromID IS NULL AND @ColumnSameSheetInheritFromID IS NULL
        SET @cellFromID = -1;

    IF @cellFromID > 0
    BEGIN
        SELECT @rowID = cls.RowValueID
        FROM dbo.[Cells] cls INNER JOIN dbo.[Columns] col ON cls.ColumnID = col.ID
        WHERE cls.ID = @cellFromID;

        IF @rowID IS NOT NULL
        BEGIN
            --GETTING REF FROM ROW RELATED TO THE RESPECTIVE DATA OF INHERITED COLUMN FROM AND CURRENT ROW              
            SELECT @cellInhValueID = cls.ID, 
                   @colFromAUX_ID = col.ColumnSameSheetInheritFromID,
                   @cellHaveValue = (IIF(cls.RowValueID IS NULL, IIF(cls.NativeValue IS NULL, 0, 1),1))

                FROM dbo.[Rows] r
                    LEFT OUTER JOIN dbo.[Columns] col
                        ON r.SheetID = col.SheetID
                    LEFT OUTER JOIN dbo.[Cells] cls  
                        ON r.ID = cls.RowID AND col.ID = cls.ColumnID
            WHERE r.ID = @rowID AND col.ID = @ColumnRelatedToFromColumnTypeID

            IF @cellHaveValue = 0 AND @colFromAUX_ID IS NOT NULL
            BEGIN
                INSERT INTO @result SELECT ID FROM dbo.GetInheritedCells(@rowID, @ColumnRelatedToFromColumnTypeID);
            END
            ELSE
            BEGIN
                INSERT INTO @result SELECT cls.ID
                FROM dbo.[Rows] r
                    LEFT OUTER JOIN dbo.[Columns] col
                        ON r.SheetID = col.SheetID
                    LEFT OUTER JOIN dbo.[Cells] cls  
                        ON r.ID = cls.RowID AND col.ID = cls.ColumnID
                WHERE r.ID = @rowID AND col.ID = @ColumnRelatedToFromColumnTypeID;
            END
        END
    END 

    RETURN;
END

Updated RowsData view:

ALTER VIEW RowsData
AS
    SELECT r.ID, s.ID SheetID, col.ID ColID, /*Columns Added*/col.ColumnSameSheetInheritFromID, col.ColumnRelatedToFromColumnTypeID,
            col.Name, ISNULL(clsVal.NativeValue, cls.NativeValue) NativeValue
    FROM Sheets s
        INNER JOIN [Columns] col ON s.ID = col.SheetID
        INNER JOIN [Rows] r ON s.ID = r.SheetID
        /*OUTER APPLY added*/
        OUTER APPLY (SELECT ID FROM dbo.GetInheritedCells(r.ID, col.ID)) inhCel
        LEFT JOIN Cells cls ON r.ID = cls.RowID AND col.ID = cls.ColumnID /* This added -> */ OR inhCel.ID = cls.ID
        LEFT OUTER JOIN [Rows] rType ON cls.RowValueID = rType.ID
        LEFT OUTER JOIN Sheets sType ON rType.SheetID = sType.ID
        LEFT OUTER JOIN Cells clsVal ON rType.ID = clsVal.RowID AND sType.WhenIsTypeShowThisColumnIDValue = clsVal.ColumnID
GO

Resultant data example:

ID          SheetID     ColID       ColumnSameSheetInheritFromID ColumnRelatedToFromColumnTypeID Name                                               NativeValue
----------- ----------- ----------- ---------------------------- ------------------------------- -------------------------------------------------- ---------------
1           1           1           NULL                         NULL                            Person Name                                        Aron
1           1           2           NULL                         NULL                            Person Country                                     Uruguay
2           1           1           NULL                         NULL                            Person Name                                        Sam
2           1           2           NULL                         NULL                            Person Country                                     NULL
3           2           4           NULL                         NULL                            Country Name                                       Uruguay
4           2           4           NULL                         NULL                            Country Name                                       USA
5           2           4           NULL                         NULL                            Country Name                                       Russia
6           3           5           NULL                         NULL                            Pet Name                                           Mickey
6           3           6           NULL                         NULL                            Pet Age                                            83
6           3           7           NULL                         NULL                            Pet Person Owner                                   Aron
6           3           8           7                            2                               Pet Country                                        Uruguay
7           3           5           NULL                         NULL                            Pet Name                                           Pluto
7           3           6           NULL                         NULL                            Pet Age                                            8
7           3           7           NULL                         NULL                            Pet Person Owner                                   Aron
7           3           8           7                            2                               Pet Country                                        Uruguay
8           3           5           NULL                         NULL                            Pet Name                                           Zabivaka
8           3           6           NULL                         NULL                            Pet Age                                            4
8           3           7           NULL                         NULL                            Pet Person Owner                                   Sam
8           3           8           7                            2                               Pet Country                                        NULL

Database script with example data to play with here!


Get this bounty!!!

#StackBounty: #ubuntu #performance Asus ZenBook Pro with Ubuntu 16.04 has massive performance drops

Bounty: 200

Background

I recently bought the Asus ZenBook Pro. I use it for testing deep learning experiments locally. These experiments are often quite compute intense both on the CPU and GPU. I’ve recently experienced some huge performance drops when doing some heavy computations.

I have Ubuntu 16.04 installed.

Problem

The problem arises when I e.g. schedule a training job using TensorFlow, Keras or running a CPU and GPU heavy job in ROS or Python. After about 30-60 seconds of expected performance (i.e good and high performance) the performance suddenly dies and the entire computer becomes almost unresponsive. A complete reboot is needed to recover functionality.

Using top, nvidia-smi or the system system monitor I see no sudden spike in any processors use of CPU or memory. No other processes starts using the CPU or GPU.

When in the unresponsive-state I also see no processors using any noticeable amount of processing power.

I suspect the power management of Ubuntu to cause the problem, since my fan is also acting uncontrollably from time to time, but I’m no linux expert. However, when I installed Ubuntu I had to do the initial boot with acpi=off if it helps.

EDIT: I have tested the same code on other computers with Ubuntu 16.04 installed and see no issues here.

I appreciate any help in locating the problem or guiding me to somewhere I can research myself.


Get this bounty!!!

#StackBounty: #magento2 #magento-2.1 #checkout #onepage-checkout #performance pages loading slow

Bounty: 100

I’m currently facing a slow page load with the checkout being the slowest of all with:

  • 28 requests
  • 18.5 KB transferred (rest cached from disk or memory)
  • Finish: 15.24s (loader disappears and the user can do something)
  • DOMContentLoaded: 6.45s
  • Load: 10.28s

Loading checkout/cart ends with:

  • 29 requests
  • 28.5 KB transferred (rest cached from disk or memory)
  • Finish: 6.35s
  • DOMContentLoaded: 1.9s
  • Load: 3.79s

whilst an empty cart has this:

  • 22 requests
  • 8.2 KB transferred (rest cached from disk or memory)
  • Finish: 2.78s
  • DOMContentLoaded: 1.22s
  • Load: 2.65s

I’m using redis for caching and all caches are active. Javascript is minified, merged and bundled as well as css and html. The server is pretty well situated with 8 CPUs, 16GB RAM and an SSD. Load etc. is never high enough to be even mentioned. Basically the server is sleeping…

There are just ~80 products and one store. We don’t use the content part of Magento. Just product detail pages, checkout and customer area (as well as backend) is served by Magento. There is a CMS system “in front” of Magento which serves pages in less than a second total including media.

I see that TTFB for the checkout document is already 5.66s. With the Magento profiler enabled I can find that magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body causes most of that time. Although it is pretty unclear what exactly causes it. Here the profiler can not help much (me at least).

magento->routers_match                                                                                                                                                                                                                                                                                            5.347600 5.347600 1  42,063,304 10,485,760
magento->routers_match->CONTROLLER_ACTION:checkout_index_index                                                                                                                                                                                                                                                    5.143997 5.143997 1  15,976,176 10,485,760
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body                                                                                                                                                                                                                                       5.143980 5.143980 1  15,975,304 10,485,760
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->EVENT:checkout_allow_guest                                                                                                                                                                                                           0.000609 0.000609 1  82.464     0         
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->EVENT:checkout_allow_guest->OBSERVER:checkout_allow_guest                                                                                                                                                                            0.000592 0.000592 1  80.944     0         
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->LAYOUT                                                                                                                                                                                                                               0.106220 0.035407 3  13,085,544 10,485,760
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->LAYOUT->layout_load                                                                                                                                                                                                                  0.000666 0.000666 1  136.56     0         
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->LAYOUT->layout_generate_xml                                                                                                                                                                                                          0.005658 0.005658 1  174.632    0         
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->LAYOUT->layout_generate_blocks                                                                                                                                                                                                       0.099472 0.099472 1  12,755,648 10,485,760
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->LAYOUT->layout_generate_blocks->MagentoFrameworkViewLayout::MagentoFrameworkViewLayout::generateElements                                                                                                                       0.099462 0.099462 1  12,902,296 10,485,760
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->LAYOUT->layout_generate_blocks->MagentoFrameworkViewLayout::MagentoFrameworkViewLayout::generateElements->generate_elements                                                                                                    0.091426 0.091426 1  11,885,184 10,485,760
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->LAYOUT->layout_generate_blocks->MagentoFrameworkViewLayout::MagentoFrameworkViewLayout::generateElements->generate_elements->EVENT:core_layout_block_create_after                                                              0.000169 0.000003 51 -16.128    0         
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->LAYOUT->layout_generate_blocks->MagentoFrameworkViewLayout::MagentoFrameworkViewLayout::generateElements->generate_elements->MagentoFrameworkViewLayout::MagentoFrameworkViewLayout::generateElements                    0.000609 0.000609 1  52.76      0         
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->LAYOUT->layout_generate_blocks->MagentoFrameworkViewLayout::MagentoFrameworkViewLayout::generateElements->generate_elements->MagentoFrameworkViewLayout::MagentoFrameworkViewLayout::generateElements->generate_elements 0.000455 0.000455 1  26.952     0         
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->LAYOUT->EVENT:layout_generate_blocks_after                                                                                                                                                                                           0.000297 0.000297 1  16.32      0         
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->LAYOUT->EVENT:layout_generate_blocks_after->OBSERVER:persistent                                                                                                                                                                      0.000279 0.000279 1  14.776     0         
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->postdispatch                                                                                                                                                                                                                         0.002972 0.002972 1  116.752    0         
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->postdispatch->EVENT:controller_action_postdispatch                                                                                                                                                                                   0.002913 0.002913 1  110.192    0         
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->postdispatch->EVENT:controller_action_postdispatch->OBSERVER:customer_visitor                                                                                                                                                        0.002900 0.002900 1  108.656    0         
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->postdispatch->EVENT:controller_action_postdispatch->OBSERVER:customer_visitor->EVENT:clean_cache_by_tags                                                                                                                             0.001175 0.001175 1  77.784     0         
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->postdispatch->EVENT:controller_action_postdispatch->OBSERVER:customer_visitor->EVENT:clean_cache_by_tags->OBSERVER:invalidate_varnish                                                                                                0.000516 0.000516 1  35.056     0         
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->postdispatch->EVENT:controller_action_postdispatch->OBSERVER:customer_visitor->EVENT:clean_cache_by_tags->OBSERVER:invalidate_builtin                                                                                                0.000629 0.000629 1  41.08      0

I also enabled the database profiler but no query takes more than 1ms even though there are almost 120 calls. But that adds up to just 120ms then.

I generated an xdebug profile locally and can see that most of time is wasted in autoloading. But I’m not sure if that’s “normal”. I just wonder why file_exists is called so often. As I was under the impression everything is precompiled and cached.
I use composer dump-autoload -o --apcu after compiling di. And of course apc is up and running.

enter image description here

enter image description here

enter image description here

enter image description here

Yet I’m stuck here for now. I don’t seem to be able to figure why TTFB is 5 secs already. And even if I solved that there is still 10 more seconds to explain and fix.
My main guess currently is that these are some xhr requests in the background blocking. Ie. I see estimate-shipping-methods only starts after an intensly long gap of about 7 seconds at 13 seconds and takes about 647ms.
Why does it wait so long to trigger that? Until that finishes the loader animation is displayed making the page seem to “hang”.

estimate-shipping-methods "delay"

checkout page load

Any input is highly welcome! I hope for a page load of 2 – 4 secs max. as that’s what I started with.

Edit:
I fixed the high TTFB. As said I’m using Redis for caching. Also for session caching but it leads to a lockup between two concurring sessions. Actually being the checkout request and the estimate-shipping-request leading to a 5 second timeout. I switched sessions back to normal file mode. Unfortunately this did not fix the long load time at all!
My current best guess is that something makes estimate-shipping-methods wait before being called resulting in a blocking of the page.
Additionally I tried to defer all JS with no change whatsoever.

Edit2:
As @peter-ocallaghan notes the problem with the checkout loading so slow (+10 secs) is actually just a chrome specific problem having the dev-console opened. Checkout/cart does not seem to be affected.


Get this bounty!!!

#StackBounty: #magento2 #magento-2.1 #checkout #onepage-checkout #performance pages loading slow -> checkout finish in 15 secs

Bounty: 100

I’m currently facing a slow page load with the checkout being the slowest of all with:

  • 28 requests
  • 18.5 KB transferred (rest cached from disk or memory)
  • Finish: 15.24s (loader disappears and the user can do something)
  • DOMContentLoaded: 6.45s
  • Load: 10.28s

Loading checkout/cart ends with:

  • 29 requests
  • 28.5 KB transferred (rest cached from disk or memory)
  • Finish: 6.35s
  • DOMContentLoaded: 1.9s
  • Load: 3.79s

whilst an empty cart has this:

  • 22 requests
  • 8.2 KB transferred (rest cached from disk or memory)
  • Finish: 2.78s
  • DOMContentLoaded: 1.22s
  • Load: 2.65s

I’m using redis for caching and all caches are active. Javascript is minified, merged and bundled as well as css and html. The server is pretty well situated with 8 CPUs, 16GB RAM and an SSD. Load etc. is never high enough to be even mentioned. Basically the server is sleeping…

There are just ~80 products and one store. We don’t use the content part of Magento. Just product detail pages, checkout and customer area (as well as backend) is served by Magento. There is a CMS system “in front” of Magento which serves pages in less than a second total including media.

I see that TTFB for the checkout document is already 5.66s. With the Magento profiler enabled I can find that magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body causes most of that time. Although it is pretty unclear what exactly causes it. Here the profiler can not help much (me at least).

magento->routers_match                                                                                                                                                                                                                                                                                            5.347600 5.347600 1  42,063,304 10,485,760
magento->routers_match->CONTROLLER_ACTION:checkout_index_index                                                                                                                                                                                                                                                    5.143997 5.143997 1  15,976,176 10,485,760
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body                                                                                                                                                                                                                                       5.143980 5.143980 1  15,975,304 10,485,760
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->EVENT:checkout_allow_guest                                                                                                                                                                                                           0.000609 0.000609 1  82.464     0         
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->EVENT:checkout_allow_guest->OBSERVER:checkout_allow_guest                                                                                                                                                                            0.000592 0.000592 1  80.944     0         
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->LAYOUT                                                                                                                                                                                                                               0.106220 0.035407 3  13,085,544 10,485,760
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->LAYOUT->layout_load                                                                                                                                                                                                                  0.000666 0.000666 1  136.56     0         
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->LAYOUT->layout_generate_xml                                                                                                                                                                                                          0.005658 0.005658 1  174.632    0         
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->LAYOUT->layout_generate_blocks                                                                                                                                                                                                       0.099472 0.099472 1  12,755,648 10,485,760
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->LAYOUT->layout_generate_blocks->MagentoFrameworkViewLayout::MagentoFrameworkViewLayout::generateElements                                                                                                                       0.099462 0.099462 1  12,902,296 10,485,760
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->LAYOUT->layout_generate_blocks->MagentoFrameworkViewLayout::MagentoFrameworkViewLayout::generateElements->generate_elements                                                                                                    0.091426 0.091426 1  11,885,184 10,485,760
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->LAYOUT->layout_generate_blocks->MagentoFrameworkViewLayout::MagentoFrameworkViewLayout::generateElements->generate_elements->EVENT:core_layout_block_create_after                                                              0.000169 0.000003 51 -16.128    0         
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->LAYOUT->layout_generate_blocks->MagentoFrameworkViewLayout::MagentoFrameworkViewLayout::generateElements->generate_elements->MagentoFrameworkViewLayout::MagentoFrameworkViewLayout::generateElements                    0.000609 0.000609 1  52.76      0         
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->LAYOUT->layout_generate_blocks->MagentoFrameworkViewLayout::MagentoFrameworkViewLayout::generateElements->generate_elements->MagentoFrameworkViewLayout::MagentoFrameworkViewLayout::generateElements->generate_elements 0.000455 0.000455 1  26.952     0         
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->LAYOUT->EVENT:layout_generate_blocks_after                                                                                                                                                                                           0.000297 0.000297 1  16.32      0         
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->LAYOUT->EVENT:layout_generate_blocks_after->OBSERVER:persistent                                                                                                                                                                      0.000279 0.000279 1  14.776     0         
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->postdispatch                                                                                                                                                                                                                         0.002972 0.002972 1  116.752    0         
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->postdispatch->EVENT:controller_action_postdispatch                                                                                                                                                                                   0.002913 0.002913 1  110.192    0         
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->postdispatch->EVENT:controller_action_postdispatch->OBSERVER:customer_visitor                                                                                                                                                        0.002900 0.002900 1  108.656    0         
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->postdispatch->EVENT:controller_action_postdispatch->OBSERVER:customer_visitor->EVENT:clean_cache_by_tags                                                                                                                             0.001175 0.001175 1  77.784     0         
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->postdispatch->EVENT:controller_action_postdispatch->OBSERVER:customer_visitor->EVENT:clean_cache_by_tags->OBSERVER:invalidate_varnish                                                                                                0.000516 0.000516 1  35.056     0         
magento->routers_match->CONTROLLER_ACTION:checkout_index_index->action_body->postdispatch->EVENT:controller_action_postdispatch->OBSERVER:customer_visitor->EVENT:clean_cache_by_tags->OBSERVER:invalidate_builtin                                                                                                0.000629 0.000629 1  41.08      0

I also enabled the database profiler but no query takes more than 1ms even though there are almost 120 calls. But that adds up to just 120ms then.

I generated an xdebug profile locally and can see that most of time is wasted in autoloading. But I’m not sure if that’s “normal”. I just wonder why file_exists is called so often. As I was under the impression everything is precompiled and cached.
I use composer dump-autoload -o --apcu after compiling di. And of course apc is up and running.

enter image description here

enter image description here

enter image description here

enter image description here

Yet I’m stuck here for now. I don’t seem to be able to figure why TTFB is 5 secs already. And even if I solved that there is still 10 more seconds to explain and fix.
My main guess currently is that these are some xhr requests in the background blocking. Ie. I see estimate-shipping-methods only starts after an intensly long gap of about 7 seconds at 13 seconds and takes about 647ms.
Why does it wait so long to trigger that? Until that finishes the loader animation is displayed making the page seem to “hang”.

estimate-shipping-methods "delay"

checkout page load

Any input is highly welcome! I hope for a page load of 2 – 4 secs max. as that’s what I started with.

Edit:
I fixed the high TTFB. As said I’m using Redis for caching. Also for session caching but it leads to a lockup between two concurring sessions. Actually being the checkout request and the estimate-shipping-request leading to a 5 second timeout. I switched sessions back to normal file mode. Unfortunately this did not fix the long load time at all!
My current best guess is that something makes estimate-shipping-methods wait before being called resulting in a blocking of the page.
Additionally I tried to defer all js with no change whatsoever.


Get this bounty!!!