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.
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
- Investigate what about the currency triggers the slower add-to-cart behaviour. eg. Try importing the Norwegian data, then translating all
Spree::Price#currencyto 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.