In a current high traffic project we noticed that the mechanism used to update radioactivity field values turns out to be very database intensive.
This seems to be due to the use of
field_attach_presave($entity_type, $entity);
field_attach_update($entity_type, $entity);
In the _radioactivity_update_energy function.
The most perfomant way to update the values seems to be using field_sql_storage_field_storage_write , which in turn can only be used on field_sql_storage based fields.
The patch attached will then detect the field storage of the radioactivity field, and then either use the existing method, or use the faster way if the field is actually sql-based. The downside of this is that update hooks are not invoked. This is ok in our use case.
This is an EXPERIMENTAL patch, we will update the issue as we test this more.
Also, feel free to say if you think this is a bad idea!
Comment | File | Size | Author |
---|---|---|---|
#3 | Overview+-+New+Relic+2015-05-04+14-33-24.png | 75.24 KB | vermario |
#2 | avoid_excessive-2480667-3.patch | 3.71 KB | vermario |
#1 | avoid_excessive-2480667-1.patch | 3.21 KB | vermario |
Comments
Comment #1
vermario CreditAttribution: vermario commentedComment #2
vermario CreditAttribution: vermario commentedWhile testing, it emerged that the previous patch would only increment the field once, this is because the field cache was not cleared after the field value was updated. This patch solves that problem.
Testing continues! :)
Comment #3
vermario CreditAttribution: vermario commentedI have done a performance and mysql volume test on a site with and without the patch.
processing 4000 emission events, these are the results:
Comment #4
vermario CreditAttribution: vermario commentedComment #5
vermario CreditAttribution: vermario commentedComment #6
evilfurryone CreditAttribution: evilfurryone at Wunder commentedThe #2 patch improved performance of the updating radioactivity values considerably. In my case it's currently ca 50% faster. Also have not detected any issues, module is working fine.
Comment #7
vermario CreditAttribution: vermario commentedWe have tested this in 2 high traffic sites, all seems well, marking this as tested.
Comment #9
vermario CreditAttribution: vermario commentedCommitted!