1

We have some high resource views that would have less impact on the overall performance if they ran at a low priority, e.g. linux nice'd to a low priority.

  • @Pierre.Vriens nice (en.wikipedia.org/wiki/Nice_(Unix)) is a way to lower the priority of a process, so allow more important things to happen. – mpdonadio Feb 6 '17 at 23:44
  • 2
    This is borderline off-topic, but since it was just asked, I am going to let it sit for a bit. – mpdonadio Feb 6 '17 at 23:45
  • There isn't anything Drupal-specific; you just use something that would be used from who is running a WordPress site, or even a plain PHP site. – kiamlaluno Feb 7 '17 at 9:26
  • PHP performance or DB performance? – mikeytown2 Feb 7 '17 at 20:28
  • I am really looking for a Drupal module or code snippet that I can insert into a request so that it executes that specific request at a lower priority. Most views are well behaved but some access a large number of rows and peg the cpu while they run. – user72407 Feb 8 '17 at 0:24
0

Well...

This is rather complicated to solve and probably not suitable for all available configurations. Given you don't reuse processes and the given php process terminates at the end of the request you can use proc_nice().

Next thing will be to be at the right spot to nice the process, does the heavy loading occur before executing? while executing? Also nicing the php process probably won't take any load of the mysql server or whatever other backend this process is requesting.

Looking at view::execute there's no way to distinguish at this point between cached views and uncached ones - so going that route we also have to nice processes which have a cache - probably something to think about.

Drupal 7 Implementation using hook_views_pre_execute().

/**
 * Implements hook_views_pre_execute().
 */
function mymodule_views_pre_execute(&$view)) {
  if($view->name=="machine_name_of_my_view") {
    // http://php.net/manual/en/function.proc-nice.php
    // Setting something higher would lead to idle only processing.
    // Please refer to the documentation of proc_nice and nice.
    proc_nice(9); 
  }
}

Drupal 8 implementation using hook_views_pre_execute():

/**
 * Implements hook_views_pre_execute().
 */
function views_pre_execute(ViewExecutable $view) {
  if ($view->id() == 'machine_name_of_my_view') {
    // http://php.net/manual/en/function.proc-nice.php
    // Setting something higher would lead to idle only processing.
    // Please refer to the documentation of proc_nice and nice.
    proc_nice(9); 
  }
}

Keep in mind that this solution requires quiet some constraints to work for you:

  • Heay load is actually in the php layer
  • proc_nice() is available (not all environments allow this)
  • dedicated php processes which terminates at the end

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.