Add to cart slow on Norway server

Summary

Adding products to cart on the Norway server has been slow for a while now, and recently had a more detailed look into it. We’ve been considering whether the server hardware was slower or that the older version of OFN (v1.2.1) was at fault, but it appears that there’s a software bug related to the currency that the server uses which makes adding a product to cart an order of magnitude slower. I’m part-way into tracking down the cause, and have yet to design a solution. It’s possible that this bug impacts not just the Norwegian server, but also other non-Australian instances.

@MyriamBoure

Technical details

I was surprised to find that the speed varies greatly between different servers. As a standardised test, I recorded the response time of the server to add the first product to the cart, and to add the 25th product to the cart. Here are the results:

Norway v1.2.1 (DO)			2 - 9 s
Norway v1.3.0-pre1 (DO)			0.7 - 4.2 s
Aus staging1 (web24)			0.5 - 6 s
UK v1.2.1 (DO)				2 - 7 s

Local v1.2.1				0.6 - 1 s
Local v1.3.0-pre1			0.1 - 0.6 s
Aus prod v1.3.0-pre1 (EC2)		0.3 - 0.6 s
Aus staging2 (DO)			0.6 - 1.4 s
Canada v1.2.1 (DO)			0.6 - ???

When I upgraded Norway to a pre-release version of 1.3 which has the add-to-cart-speed improvements, it got faster, but not on par with the Australian servers.

When I loaded the Norwegian server’s data onto my local computer, it ran fast. However, once I changed my local config/application.yml file’s currency to 'NOK', then it started running slow, which seems to implicate something price-related.

Running with that configuration, I followed the trace of where the slowness was coming from. Here’s the call stack as far as I followed it:

OrdersController#populate
fire_event('spree.order.contents_changed')
Order#update_distribution_charge!
EnterpriseFeeCalculator#create_line_item_adjustments_for
EnterpriseFeeApplicator#create_line_item_adjustment
EnterpriseFee#create_locked_adjustment
Adjustment.create
Adjustment#update_adjustable
Order#update
OrderUpdater#update

Next steps

  • Investigate what about the currency triggers the slower add-to-cart behaviour. eg. Try importing the Norwegian data, then translating all Spree::Price#currency to AUD. Or try importing Aus staging data, and go in the other direction.
  • Isolate an operation that runs slow with NOK and fast with AUD. Use this to understand why a change in currency would reduce the performance.

Thank you @RohanM for taking the time to investigate on that issue, well done! And as you say it seems also to impact UK and other non Australian servers.
Ping @Olivier, @sigmundpetersen, @CynthiaReynolds, @marito59, @gnollet, @NickWeir for info.

For info @Nicolas, I guess this has also an impact on the French instance.

Following this conversation: Cart doesn't update and can't checkout!

One more comment: I just tried an order of 80 products and crashed the platform. Interestingly enough, once I restarted it and went back to the shop from the 80 products were still there selected and I could this time proceed to checkout (but remove or add just 1 product and it will start rolling again and crash…).

strange, possibly related problem? Unable to scroll down the cart to checkout when #products>10-15 - really should be fixed unless they’re running a very old version

I have a branch with some speed improvements written and awaiting testing. Once that’s through it should be feasible to work with carts up to 100 items and still be able to add/remove items within about 10 secs (not great, but workable, and much improved on the old system, which took >5 mins for the same operation).

Great to know @RohanM!
When do you think it will be merged? We will wait for it to do the the upgrade and launch our next order cycle & test it at the same time, so that’s great if we can plan a bit to inform our members :slight_smile: … ping @sigmundpetersen

Also regarding what you said above:

Is the fix linked to that? I guess @NickWeir will be interested as well as I guess it would also improve the performance for UK in that case?

It’s likely that it’ll be merged mid-late next week. I think @sstead will be back then so we can test it and make sure everything’s working.

This will improve the speed of adding products to the cart for everyone, but it won’t affect the shopfront loading speed, which is the main problem in the UK. But I’ll be looking at that issue soon.

Cheers,
Rohan

1 Like

Testing done- is merged on Australia’s production site :slight_smile:

Yearrrrr! hank you @sstead :slight_smile: Does it mean we can do another upgrade now to see it on the Norwegian platform? Is this already in the last version of the master branch? Or do we have to still wait a little bit and how long then?

Ping @sigmundpetersen, @Olivier and @CynthiaReynolds, hope that will solve our crashing issue :slight_smile:

@sigmundpetersen which version have you merged yesterday? I just tested and I could add 116 products without any problem on the button “add to cart” (see screen shot… in norwegian now!), it seemed ok… until I clicked on “edit cart” and then it turn, turn, turn and doesn’t go to the basket page, got the grumpy cat and crashed the platform :frowning:
Maybe I’m just impatient and it had not been merged before @sigmundpetersen did the upgrade yesterday night… I know I’m impatient, but we are waiting for that fix to launch our next order cycle :wink:

Ok, going further, even stranger… now, when the platform has crashed and we have restarted it, when I try to reconnect with the same browser where I crashed the platform (chrome), I can’t access it at all I go directly to the grumpy cat! I tried to close and reopened Chrome, and I still can’t access the platform. It works on other computers. I tried to open a new window on Chrome on private navigation and it works. I go back to a regular chrome window and again the grumpy cat… We managed to get out of it only on deleting all the OFN cookies from the Chrome browser… I never had this problem before, before when it was crashing we could reconnect and the products where in the baskets and we could proceed to checkout…

Huraaaaaaa! A big big hug to @RohanM for fixing that @sstead for testing :slight_smile: THAT WORKSSSSSS!!! Ping @sigmundpetersen and @CynthiaReynolds. Sigmund had updated to the 1.3.1 and not the lateste master branch code, but he upgraded again and that works, no more problem!!! The issue I mentionned with having to empty all the OFN coockies is still a bit strange, but not connected to that. The store was on “not active” payment system, but still it should have redirected me to the main page… anyway, let’s go back to the JOY of having this big issue solved. THANK YOU, I love you :slight_smile:

1 Like

Yay, glad it’s working! I’m not sure what was happening with the cookies-related issue, but I’ll keep an eye out for it. Fingers crossed all is well the next order cycle! :smile: