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!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

vermario’s picture

vermario’s picture

While 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! :)

vermario’s picture

I have done a performance and mysql volume test on a site with and without the patch.

processing 4000 emission events, these are the results:

graph

vermario’s picture

Status: Active » Needs review
vermario’s picture

Issue summary: View changes
evilfurryone’s picture

The #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.

vermario’s picture

Status: Needs review » Reviewed & tested by the community

We have tested this in 2 high traffic sites, all seems well, marking this as tested.

  • vermario committed 14e680e on 7.x-2.x
    Issue #2480667 by vermario: Avoid excessive database activity when using...
vermario’s picture

Status: Reviewed & tested by the community » Fixed

Committed!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.