skip to Main Content

I have a laravel artisan command that takes a page of 250 orders from Shopify and does an insert on duplicate key MySql query. It runs really well on local (still hitting the real shopify Api), it processes a batch of 250 in less than a second. When I pushed it to the server, it is SUPER slow on the part below(about 3.5 minutes for the same batch of 250). The sql query itself is still very speedy, but this data prep is SO slow. It is taking the orders by line item and formatting it for the value part of the insert statement:

        $items = $order["line_items"];
        $this->info($order["id"]);
        foreach ($items as $item) {
          $value = "(" .
          "'" .     now()                   . "',".
          "'" .     now()                   . "',".
          "'" . addslashes($item["id"]) . "'," .
          "'" . addslashes($order["id"]) . "'," .
          "'" . addslashes($order["created_at"]) . "'," .
          "'" . addslashes($order["email"]) . "'," .
          "'" . addslashes($order["name"]) . "'," .
          "'" . addslashes($item["sku"]) . "'," .
          "'" . addslashes($item["title"]) . "'," .
          "'" . addslashes($item["price"]) . "'," .
          "'" . addslashes($item["quantity"]) . "'"
          ."),";
          array_push($values, $value);
        }
      $since_id = $order["id"];
      }

Server is a 2 core 8gb ram Amazon Lightsail machine. When I look at resource usage while the command is running, there is PLENTY of ram available and the CPU barely even shows an increase (never goes above 1%). What can I change either in this code, or in my server config to get better performance. Thanks.

2

Answers


  1. Chosen as BEST ANSWER

    I pushed the changes but never pulled them onto the server. Works fine now...


  2. Have you tried to disable firewall or open an exception? Try it. Also try to clean the caches:

    php artisan cache:clear
    php artisan config:clear
    php artisan config:cache
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search