Skip to content

Hash based spread to produce even load on the system #1

@francisdb

Description

@francisdb

I would be interested in support for the jenkins cron syntax, using a hash of some identifier they do a deterministic spread of cron jobs. eg H/15 would for example give you execution at 4.234 / 19.234 / 34.234 / 49.234 th minute. Even on a restart/reschedule with the same Id you will end up with these execution times.

To allow periodically scheduled tasks to produce even load on the system, the symbol H (for “hash”) should be used wherever possible. For example, using 0 0 * * * for a dozen daily jobs will cause a large spike at midnight. In contrast, using H H * * * would still execute each job once a day, but not all at the same time, better using limited resources.

https://github.com/jenkinsci/jenkins/blob/master/core/src/main/resources/hudson/triggers/TimerTrigger/help-spec.html#L38

Implementation is done like this:

  1. Use the provided id and make a hash (md5)
  2. use that hash to initialize Random
  3. use this random to replace the H values

https://github.com/jenkinsci/jenkins/blob/master/core/src/main/java/hudson/scheduler/Hash.java

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions