razorpay / razorpay-magento

Razorpay Payment Extension for Magento
28 stars 38 forks source link

High memory and cpu usage with the cron jobs #499

Open noeli-getjohn opened 4 weeks ago

noeli-getjohn commented 4 weeks ago

Hello,

We installed this extension v4.1.6 on our Magento(v2.4.5-p2) site recently. But we got very high memory and cpu usage with the cron group "razorpay", which made the server crash. In our investigation, we found two critical issues in your module.

  1. When Razorpay\Magento\Cron\UpdateOrdersToProcessing is run, we got this error in the line 188. Cron Job razorpay_update_order_to_processing has an error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'rzp_update_order_cron_status' in 'where clause' It means the sales_order table is missing the column razorpay_update_order_to_processing. So we checked Razorpay\Magento\Setup\UpgradeSchema and found an issue in the line 78. Current code: $tableName = $setup->getTable(OrderLink::TABLE_NAME); I think it should be $tableName = $setup->getTable('sales_order');.

  2. When Razorpay\Magento\Cron\CancelPendingOrders is run, the excution time takes forever in the line 117. The error: Could not acquire lock for cron job: razorpay_cancel_pending_orders So it uses a lot of memory and cpu. Ther reason is because we have a lot of the orders and specially, a lot of the pending orders. total orders number: 85k total pending orders number: 35k So it's taking too much time to get these pending order. I don't think it needs to get all the pending orders before the pending order timeout because the cron job is run per 5 mins. If so, it will make the same issue for all the sites having lots of pending orders. I think there should be a minium time limit to add to the searchCriteria filter that considers if the site doesn't have the cron install for some reason for a while. It will solve the issue.

We forked your repository and fixed the issues in those way. Now the cron jobs work perfectly and solved the high memory and cpu usage issue. We will make a pull request with those fixes soon. If you merge it or make better fixes for the issues, we can install this module from your github repo by composer.

Hope to hear from you soon. Thanks!

yashgit891 commented 2 weeks ago

@noeli-getjohn thank you for reaching out with these findings:-

  1. For point 1 the UpdateOrdersToProcessing is available for old users of the plugin as modifications were made to the Update orders cron. So by default the UpdateOrdersToProcessingV2 cron is enabled for all and UpdateOrdersToProcessing is disabled for all. In your case it it not needed to enable the UpdateOrdersToProcessing cron.

  2. For point 2, the issue mentioned is valid and we will be adding setting where user can select the time duration of orders which the cron should consider. Marking this as an enhancement and will release a new version in sometime with this change.