Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CPU is utilizing 100% resource and therefore Queue failed

My code is like below.

for($i = 0; $i <= 100; $i++) {
    $objUser = [
        "UserName"      =>  $request["UserName"] . $i,
        "EmailAddress"  =>  $request["EmailAddress"] . $i,
        "RoleID"        =>  RoleEnum::ProjectManager,
        "Password"      =>  $request["Password"],
    ];
    $RegisterResponse = $this->Register->Register($objUser);
    $Data = $RegisterResponse["Data"];                
    $job = (new AccountActivationJob($Data));
    dispatch($job);
}

Above code is creating 100 users and Each time a queue is being created to send email notification. I am using database default queue.

I have shared hosting account on GoDaddy. Due to some reasons the CPU usage reaches 100. Here is the screenshot.

enter image description here

Finally loop stops in between. Below is the screenshot after 5 mins.

enter image description here

Here, My problem is: It is not able to continue creating 100 users. I am doing this to test the sample queue implementation where multiple users send request for registration. Am I doing anything wrong?

like image 403
Pankaj Avatar asked Mar 26 '17 17:03

Pankaj


People also ask

Why is my CPU usage at 100%?

If the CPU usage is around 100%, this means that your computer is trying to do more work than it has the capacity for. This is usually OK, but it means that programs may slow down a little. Computers tend to use close to 100% of the CPU when they are doing computationally-intensive things like running games.

How do you find the root cause of high CPU utilization?

Use Task Manager to view CPU consumption to help identify the process or application that's causing high CPU usage: Select Start, enter task, and then select Task Manager in the search results. The Task Manager window defaults to the Processes tab.

How do I troubleshoot CPU usage in vmware?

Increase the amount of memory allocated to the virtual machine. This can potentially decrease disk and/or network activity for applications that cache. This might lower disk I/O and/or network traffic, which could in turn reduce CPU utilization.


1 Answers

As stated above, GoDaddy has a lot of resource limitations. You can only send 100 Emails an hour is what I have heard.

That also not at a single time. If it detects you are sending a lot of emails, your process is blocked.

Instead, you can queue up the messages to be sent 1 per 20 seconds or 30 seconds. It will help keep the resources in limits, and your emails are sent to the customers without any problem.

You can use the sleep function for this.

like image 160
Tanay Avatar answered Sep 30 '22 10:09

Tanay