owebia / magento2-module-advanced-shipping

Other
91 stars 29 forks source link

Slow recalculatation of shipping cost #7

Closed tlygnersjo closed 7 years ago

tlygnersjo commented 7 years ago

Hi,

I'm using your plugin to calculate shipping based on zip code ranges and having a problem with execution time for the ajax refresh of the cart.

I tried execute everything thats not connected to Owebia extension (zip code range generation and checks) on a separate php file and that took 0.8 seconds to execute. If I check the load times for ajax in Magento2 it took about 1-20 seconds to load the ajax call (even with a single addMethod).

This is the code I'm using ATM:

addMethod('pickup_in_store', [
  'title' => "Pickup in store",
  'price' => 0,
]);

What could possibly be wrong? How can i debug this further?

Thanks in advance!

owebia commented 7 years ago

Can it be a Magento Cache issue ? 1 to 20 seconds, it is a big range

tlygnersjo commented 7 years ago

Sorry my bad, it should have said 10-20 seconds.

Some information:

Cache status:

Is there something else that can be wrong with my setup? Should checkout be slow? From what i've found checkout is not cached at all in Magento 2?

network-speed

shipping-methods
owebia commented 7 years ago

What is the configuration of Advanced Shipping Setting ? Are you adding only one method ?

owebia commented 7 years ago

Can you:

  1. Activate the debug option
  2. Make a shipping estimation
  3. Click on the bug icon in "Configuration" field At the end of the debug informations (open the last block), you will see the duration
tlygnersjo commented 7 years ago

Yes thats the only shipping method i use in Advanced Shipping Setting.

If i follow your steps and enable debug (Debug = yes), clear the cache and goes to checkout to do a shipping estimation it loads for at least 5 minutes (probably for an eternity). Also one apache2 process gets stuck at around 30-50% cpu usage and 5% memory until i reboot apache and disable debug in your extension. If then go to checkout it behaves as I initially described and no apache2 processes "hangs".

Also if I open up the debug log i get a 500 internal server error.

owebia commented 7 years ago

Is it possible that you have a side effect with another extension and Advanced Shipping Setting ?

It is normal if you get an internal server error when the debug file doesn't exist (I have to fix this but it is not a big problem).

Magento 2 can deploy some files at runtime depending on the configuration of your store.
If you have cleared the cache, it can explain a part of the resources used to rebuild the cache.

What is your server configuration ?

Are you using setup:di:compile and setup:static-content:deploy commands ?

tlygnersjo commented 7 years ago

I've disabled as much modules as i could (the ones that is not used) for checkout. I'm using your Advanced Setting Core + Advanced Shipping Setting and also Flat Rate module (at the moment) because Magento2 needs one base shipping method in order to recalculate the cart.

Oh okay.

I've tried both with and without clearing the cache. Is the checkout cached? I tought it was not cached at all.

I've got 2x Intel Xeon DC X5450 3.0GHz, 32GB ram, 2x SAS harddrives in RAID 1 (HP DL360 G6) at colocation. It is running XEN and this VPS for magento is running on top of XEN virtualization (all CPU power, 4GB dedicated ram and unsure how much disk space but shouldn't matter). That is a dedicated server for our company and got a low load (its main purpose is development and serving couple of lightweight projects with low traffic volume).

Yes I've compiled through "setup:di:compile" and using "setup:static-content:deploy".

List of enabled modules: Magento_Store Magento_AdvancedPricingImportExport Magento_Directory Magento_Theme Magento_Backend Magento_Backup Magento_Eav Magento_Customer Magento_BundleImportExport Magento_CacheInvalidate Magento_AdminNotification Magento_Indexer Magento_CatalogImportExport Magento_Cms Magento_Rule Magento_Catalog Magento_Search Magento_CatalogUrlRewrite Magento_Widget Magento_Quote Magento_CheckoutAgreements Magento_SalesSequence Magento_CmsUrlRewrite Magento_Config Magento_ConfigurableImportExport Magento_Msrp Magento_Contact Magento_Cookie Magento_Cron Magento_CurrencySymbol Magento_Bundle Magento_CustomerImportExport Magento_Deploy Magento_Developer Magento_Authorization Magento_Downloadable Magento_ImportExport Magento_Payment Magento_Email Magento_User Magento_Sales Magento_CatalogInventory Magento_GoogleAnalytics Magento_Ui Magento_GroupedImportExport Magento_GroupedProduct Magento_DownloadableImportExport Magento_Checkout Magento_Security Magento_LayeredNavigation Magento_Marketplace Magento_MediaStorage Magento_CatalogRule Magento_Multishipping Magento_ConfigurableProduct Magento_Newsletter Magento_OfflinePayments Magento_SalesRule Magento_PageCache Magento_Captcha Magento_Vault Magento_Persistent Magento_ProductAlert Magento_ProductVideo Magento_Reports Magento_RequireJs Magento_Review Magento_Rss Magento_CatalogRuleConfigurable Magento_Paypal Magento_OfflineShipping Magento_GoogleAdwords Magento_SampleData Magento_CatalogSearch Magento_Integration Magento_Shipping Magento_Sitemap Magento_NewRelicReporting Magento_Swagger Magento_Swatches Magento_SwatchesLayeredNavigation Magento_Tax Magento_TaxImportExport Magento_GiftMessage Magento_Translation Magento_GoogleOptimizer Magento_UrlRewrite Magento_EncryptionKey Magento_Variable Magento_Version Magento_Webapi Magento_WebapiSecurity Magento_Weee Magento_CatalogWidget Magento_Wishlist Owebia_AdvancedSettingCore Owebia_AdvancedShippingSetting

List of disabled modules: Magento_Dhl Magento_Fedex Magento_Authorizenet Magento_SendFriend Magento_Ups Magento_Usps Magento_Braintree

owebia commented 7 years ago

There are multiples elements that can be cached : config, translations, templates...
Some elements are cached for the checkout page.

Do you minify JS and CSS ? I have encountered some issues when trying to minify them in Magento.

Are you able to add debug code in files to find what is so long ?

tlygnersjo commented 7 years ago

Right now I'm having cache enabled for this: Current status: config: 1 layout: 1 block_html: 1 collections: 1 reflection: 1 db_ddl: 1 eav: 1 customer_notification: 1 full_page: 1 config_integration: 1 config_integration_api: 1 translate: 1 config_webservice: 1

tlygnersjo commented 7 years ago

Yes, minify is enabled for both CSS and JS and also bundling/merging. I'll try to disable those options and see if that makes any difference.

I've got full access to the web server/site and I'm a developer so that should not be a problem. Could you tell me what to add and where?

Thanks for the help so far!

owebia commented 7 years ago

Please try first by disabling css and js merging and bundling.

tlygnersjo commented 7 years ago

I've tried without css and js bundling/minify now and it took 30 seconds at first try and 57s second try. One thing i noticed while it was loading for 30-57s, the whole time i got a 100% CPU load at the apache process. As soon as it was done the CPU load dropped.

This is the JSON response i'm getting (shouldn't take 30-60 seconds to generate):

[
  {
    "carrier_code":"owsh1",
    "method_code":"pickup_in_store",
    "method_title":"Pickup in store",
    "amount":0,
    "base_amount":0,
    "available":true,
    "error_message":"",
    "price_excl_tax":0,
    "price_incl_tax":0
  },
  {
    "carrier_code":"flatrate",
    "method_code":"flatrate",
    "carrier_title":"Flat Rate",
    "method_title":"DB Schenker",
    "amount":200,
    "base_amount":200,
    "available":true,
    "error_message":"",
    "price_excl_tax":200,
    "price_incl_tax":200
  }
]
owebia commented 7 years ago

What is displayed in the debug output of Advanced Shipping Setting ? You must see the duration of generation.

tlygnersjo commented 7 years ago

The JSON response above is from my browser (Developer tool > Network > Response).

I can still not get "Debug" in Advanced Shipping Setting to work. When i activate debug, its an infinite load time for ajax in checkout (it never stops load) and i also checked log for debug and the only thing i see is "Carrier[owsh1].getConfig" and if i click on that its empty.

If i open "magento_path/var/log/owebia_advancedsettingcore.log" i see this:

<div class="panel panel-primary">
    <div class="panel-heading" role="tab" id="heading-id581331934a533">
        <h4 class="panel-title">
            <a role="button" data-toggle="collapse" href="#id581331934a533" aria-expanded="true" aria-controls="id581$
                Carrier[owsh1].getConfig
            </a>
        </h4>
    </div>
    <div id="id581331934a533" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading-id581331934a53$
        <div class="panel-body">
owebia commented 7 years ago

Ok, is it possible to have an access to your server ?

tlygnersjo commented 7 years ago

Yes what sort of access do you need? Login to Magento store or root access to web server?

If you need root access I can do that if you can connect through Teamviewer and I'll have the terminal ready? It's not that i don't trust you but i need to have control of whats happening and dont want to leave a root password out to somebody.

Let me know when you're able to fix it and we will fix that. Maybe the easiest thing would be to add each other on Skype and take it from there? @owebia

owebia commented 7 years ago

Sorry for the delay.

I can connect through TeamViewer. My Skype ID is owebia.

tlygnersjo commented 7 years ago

It's okay!

I've now added you on Skype. Let me know when you're able to connect through TeamViewer and we'll take it from there.

owebia commented 7 years ago

This was a large array processing issue. For people reading this thread, remember that the configuration is not executed as PHP code, it is parsed and evaluated.

If you can, avoid repetition of code execution and try to optimize your configuration.