-
-
Notifications
You must be signed in to change notification settings - Fork 439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve post-checkout reindexing #152
Comments
Interesting.. Also worth noting is that |
While we are discussing this I guess I should also point out that there is
at least one instance of an index temp table being a real table and causing
race conditions. I'll have to find it later and point it out.
…On Thu, Jan 5, 2017 at 1:55 PM, Colin Mollenhour ***@***.***> wrote:
Interesting.. Also worth noting is that ALTER TABLE causes in-progress
transactions to be implicitly committed. I didn't look to see if these
happen in the middle of a transaction or not but I'm definitely in favor of
completely removing support for MyISAM wherever possible (see #105
<#105> for all reasons).
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#152 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAC5Ggo4W-6it2bTBni5A8jppoAuF0AFks5rPTyqgaJpZM4Lb_Gu>
.
|
Following up on this I've been looking into the indexing that happens during checkout (specifically price & stock). I was seeing a couple of database errors when many orders were placed simultaneously:
There are a few requirements to see this behaviour:
While looking for the solution I found a few issues: Some database transactions with missing/unsafe try catch blocks (though most are probably harmless) The rest of the issues are related to Mage_CatalogInventory_Model_Observer::reindexQuoteInventory(): Stock & price indexers are called directly, bypassing the indexer locking and mode check.
If a product's stock status is likely to change (ie. it has fallen below the minimum qty) then its stock item is saved
That last point is where things get very confusing - products are re-indexed multiple times:
Step 2a. results in calls to
EDIT: The stock indexer will run 2 times, the price indexer 2 times, and if set to real-time mode these indexers will run once: catalog_product_attribute, catalogsearch_fulltext I'm just guessing really, but I think the original intention was to make sure the price indexer runs after the stock indexer, because the price index is responsible for hiding out of stock products. But it looks like the logic has been duplicated and is being run twice, once by I've created a couple of branches with a proof of concept alternative solution: |
Here's a version I've been using in production I doubt it can be accepted in its current state, but I'm unable to spend any more time on it so I'm leaving it here in case anyone else is interested. The main benefits I've seen are:
|
This is excellent work, @bob2021! I don't have time to play with it at the moment but I would love to see this type of improvement get merged. I'd encourage you to go ahead and submit a PR, but just don't expect it to be merged really soon since it is pretty deep. |
Thanks, I've split it up into a few PRs to try and make it easier |
Firstly, thanks for the effort here. Wanted to share a thought/idea with you, related to this topic, and get some feedback. So, my thought is as thus: If a product is not setup to do stock management, then is there any need to even initiate a re-index for stock (and price) for said product? I would think no. Resulting code/patch that I done to eliminate those products:
Thoughts? See any issue I did not consider? |
Any thoughts on this? Did you maybe find some time to test this / or even run in a production env? |
I have been using this in a production environment for about 7 months now. Not implemented as a patch, but extended the actual observer with a custom module. We used to have a lot of checkout lock issues, which was identified as stock indexing locking the tables, and caused issues with checkout (ye old lock table timeout error) especially under big load (major promotional periods) I had actually forgotten about this code, most likely as we have never had any lock timeouts again. I have this in my custom module for overriding the observer
and my custom class obviously extends the core one
and my method:
It is from this I derived the previously noted patch |
…ducts that manage stock * Limit post-checkout stock re-index to only products that manage stock. * Restrict collection to just one column in result. Cast id values to int prior to usage in SQL IN statement refs: OpenMage#152
…ducts that manage stock * Limit post-checkout stock re-index to only products that manage stock. * Restrict collection to just one column in result. Cast id values to int prior to usage in SQL IN statement refs: OpenMage#152
OpenMage#562) * Limit post-checkout stock re-index to only products that manage stock. ref OpenMage#152 * Restrict collection to just one column in result. Cast id values to int prior to usage in SQL IN statement
…ducts that manage stock * Limit post-checkout stock re-index to only products that manage stock. * Restrict collection to just one column in result. Cast id values to int prior to usage in SQL IN statement refs: OpenMage#152
OpenMage#562) * Limit post-checkout stock re-index to only products that manage stock. ref OpenMage#152 * Restrict collection to just one column in result. Cast id values to int prior to usage in SQL IN statement
…ducts that manage stock * Limit post-checkout stock re-index to only products that manage stock. * Restrict collection to just one column in result. Cast id values to int prior to usage in SQL IN statement refs: OpenMage#152
…ducts that manage stock * Limit post-checkout stock re-index to only products that manage stock. * Restrict collection to just one column in result. Cast id values to int prior to usage in SQL IN statement refs: OpenMage#152
@bob2021 Suffering quite badly with timeouts at checkout in our shop and we have a lot of stock that needs inventory managed. Do you know if your modifications (the one you share as having been run in production) still works OK and is believed safe to put into production? Thanks for yours (and everyone else's) hard work on figuring this out! |
Hi @doctea, I left the job where I was working on this a few years ago so I can't say for sure if the changes still work ok. They were certainly running in production at the time I originally created this issue, but unfortunately that doesn't mean they will work well in your specific Magento deployment or that problems weren't found after I left that I just don't know about. From the comments on some of the PRs it seems like these patches have issues with 3rd party indexing modules. What tables are you seeing lock timeouts on? |
Thanks for getting back to me, @bob2021 ! Seeing sporadic timeout problems in many different tables, mostly customer and sales related. (Perhaps I'm conflating multiple issues but my investigations lead me here anyway -- timeouts seemed to surround order creation/indexing mostly). I also found some problems when using the MantiCorp_SphinxSearch module (DDL statements can't be executed in a transaction..) but I think I found a way to work around that. In the end I found that hundreds of downloadable products had stock management enabled unnecessarily, so I've disabled all of those and hopefully that'll solve the issue. I've got a local branch based on your patch ready to try if that doesn't work though :) Thanks again! |
…ducts that manage stock * Limit post-checkout stock re-index to only products that manage stock. * Restrict collection to just one column in result. Cast id values to int prior to usage in SQL IN statement refs: OpenMage#152
there are many PRs linked to this issue, thanks to the original author ;-) |
Not 100% correct. This is an overall discussion on the topic. The merge you are refering to was here: #562 |
@ProxiBlue Okay, thanks for making it clear. |
Some PRs were merged, some were closed, I think the whole thing would have to be rediscussed based on the current codebase. For the time being I'll close this. Such wide, complex and old topics are impossible for us to re-start now. In case new PRs arise I'll make sure to test them as soon as possible but leaving this open doesn't help anybody anymore. |
Many of the indexers call
Mage_Index_Model_Resource_Abstract::disableTableKeys()
, which runs a statement like this:ALTER TABLE ... DISABLE KEYS
. Then, after some rows are inserted into the index table,enableTableKeys()
is called.As far I can see
DISABLE/ENABLE KEYS
only works with MyISAM tables, so it isn't used by modern Magento installations. What's worse is in MySQL 5.5+ theALTER TABLE
statement requires a table metadata lock.As the statement doesn't actually do anything it could be removed and the lock would be avoided (though its possible it might cause problems for older installations that might still have MyISAM tables)
It may seem like it wouldn't have that much impact as the lock should only be for a very short time, but in production I've seen large queues of queries 'Waiting for table metadata lock' on tables like cataloginventory_stock_status and catalog_product_index_price when the ALTER TABLE statement is blocked by some other very slow transaction.
The text was updated successfully, but these errors were encountered: