For site with a huge set of active sensors it leads to visible performance degradation inside `monitoring_sensor_result_last` function.
Suggestion: add an db index for the timestamp field.

CommentFileSizeAuthor
#9 2970995-9.patch737 bytesdmitrii
#7 2970995-7.patch914 bytesdmitrii
#4 2970995-4.patch905 bytesdmitrii
#2 2970995-1.patch900 bytesdmitrii

Issue fork monitoring-2970995

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

dmitrii created an issue. See original summary.

dmitrii’s picture

StatusFileSize
new900 bytes

Status: Needs review » Needs work

The last submitted patch, 2: 2970995-1.patch, failed testing. View results

dmitrii’s picture

StatusFileSize
new905 bytes

use old array syntax

dmitrii’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 4: 2970995-4.patch, failed testing. View results

dmitrii’s picture

Status: Needs work » Needs review
StatusFileSize
new914 bytes

fix parameter order for `watchdog`

berdir’s picture

+++ b/monitoring.install
@@ -57,8 +57,25 @@ function monitoring_schema() {
+ */
+function monitoring_update_7001() {
+  try {
+    db_add_index('monitoring_sensor_result', 'timestamp', array('timestamp'));
+  }
+  catch (DatabaseSchemaObjectExistsException $exception) {
+    watchdog('monitoring', 'The timestamp index already exists.');
+  }
+  catch (Exception $exception) {
+    watchdog('monitoring', $exception->getMessage(), WATCHDOG_ERROR);
+    throw new DrupalUpdateException($exception->getMessage());
+  }

the index already existing check can be verified first, then you don't need that catch. also imho it is very unlikely to fail when checking that we and we could just leave the try/catch out.. update process catches every exception and reports them, I never do that in my own update functions.

dmitrii’s picture

StatusFileSize
new737 bytes

@Berdir addressed. Thanks!

The last submitted patch, 7: 2970995-7.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 9: 2970995-9.patch, failed testing. View results

berdir’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev
berdir’s picture

Priority: Normal » Major
Status: Needs work » Needs review

Rediscovered this on D8 as well, but just timestamp isn't enough, needs an index with sensor name as well.

This drops the cost of monitoring_sensor_result_last() from 1.4s to 50ms for me on 11.3 and 11.4 will hopefully improve it further with improved entity queries.

berdir’s picture

Title: Missing db index on the timestamp field » Missing indexes for sensor name and timestamp
berdir’s picture

Status: Needs review » Fixed

Merged.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • berdir committed 6db85581 on 8.x-1.x
    fix: #2970995 Missing indexes for sensor name and timestamp
    
    By: dmitrii...

Status: Fixed » Closed (fixed)

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