Coder Social home page Coder Social logo

jobq's Introduction

Jobq

Simple job queue management (a better 'batch')

jobq manages a simple batch queue, where one job is run after the other. Many queues can be run independently, and no specific privileges or daemon is required. Queue info and statistics are syslogged.

It is especially useful for complex crontabs, to force sequential execution of jobs that would otherwise run in parallel with unlimited instances. Jobs and load can be regulated by 'run queues' very easily with jobq.

jobq is licensed under the GNU GPL 3.0.

Example usage

Run two heavy jobs: first one is run immediatly since queue is initially empty (shows in processes but not in queue), the second one is waiting (shows in queue).

hal:~$ jobq heavy_job arg1
hal:~$ jobq heavy_job arg2 param2

hal:~$ pgrep -lf heavy_job
10441 /usr/bin/heavy_job arg1

hal:~$ jobq
ID     Submission date      Command
10447  2009-10-27 16:06:59  heavy_job arg2 param2

hal:~$ tail /var/log/user.log
Oct 27 16:06:52 hal jobq: queue runner started for user/queue 'foo/default' (pid 10421)
Oct 27 16:06:52 hal job[foo/default/10413]: start (delay:0 sec, todo:0): heavy_job arg1
Oct 27 16:07:22 hal job[foo/default/10413]: done (time:30 sec, exit:0)
Oct 27 16:07:22 hal job[foo/default/10447]: start (delay:23 sec, todo:0): heavy_job arg2 param2
Oct 27 16:07:27 hal job[foo/default/10447]: done (time:5 sec, exit:0)

First job was scheduled and started at 16:06:52 and took 30 sec to complete.

Second job was scheduled 7 seconds later at 16:06:59 (not logged), started at 16:07:22 (23 sec after sheduling) and took 5 sec to complete.

Job queue monitoring

jobq-profile prints time and calls per script:

$ jobq-profile -q production

Calls  Time(sec)  Command
   12     460504  ./script/runner "LivePush.clean" && ./script/pates 
  197      49165  rake -s import:foobar:home_news_competition
  201      35767  rake -s import:foobar:news
  492       3063  rake -s import:foobar:update_recent_game_squad
   [...]

jobq-stat compile some statistics from logged timings and give you an overview of your queue health (it calls ''jobq-profile''):

$ jobq-stat -q production

Current job queue size  : 6 pending jobs
Oldest queued job posted: 4 minute(s) ago

Job execution statistics from 'Apr 12 16:50:02' to 'Apr 16 17:39:25'
(extracted from /var/log/user.log):

  Total jobs launched   : 4300
  Average job queue size: 170
  Maximum job queue size: 1817
  Average job delay     : 77 minute(s)
  Maximum job delay     : 846 minute()s
  Longest job exec time : 43779 second(s)
  Longest job command   : ./script/runner "LivePush.clean" && ./script/pates

Calls  Time(sec)  Command
   12     460504  ./script/runner "LivePush.clean" && ./script/pates 
  197      49165  rake -s import:foobar:home_news_competition
  201      35767  rake -s import:foobar:news
  492       3063  rake -s import:foobar:update_recent_game_squad
  489       3035  rake -s import:foobar:update_recent_game_information
  489       2949  rake -s import:foobar:update_ranking_just_after_game
  197       1864  rake -s import:foobar:home_news
   65        867  rake thinking_sphinx:index > /dev/null 2>&1 
    3         16  ./script/runner "LivePush.clean" 
    2         16  rake -s import:foobar:update_recent_end_game_squad
    2         16  rake -s import:foobar:update_ranking_during_one_day
    2         15  rake -s import:foobar:update_recent_end_game_information

Pending jobs:
  ID     Submission date      Command
  29092  2010-04-16 17:35:01  rake -s import:foobar:home_news 
  29791  2010-04-16 17:36:01  rake -s import:foobar:update_ranking_just_after_game 
  29790  2010-04-16 17:36:01  rake -s import:foobar:update_recent_game_information 
  29788  2010-04-16 17:36:01  rake -s import:foobar:update_recent_game_squad 
  30842  2010-04-16 17:38:01  rake -s import:foobar:update_ranking_just_after_game 
  30841  2010-04-16 17:38:01  rake -s import:foobar:update_recent_game_information 

Real life sample

The following picture is a 'load graph' from a server with a large crontab, launching many jobs at different frequency, from every minute to every month. Of course, sometimes jobs overlap badly, and if they compete for a scarce ressource (such as I/O on a local disk) they are slow and also slow down the whole server. Those load graphs often exhibits horizontal "plateaus" close to integer values, a sign that you have long running processes which stack up and eat all your server ressources.

jobq effect

On Tuesday all jobs where run through a single queue by simply prepending 'jobq' to the existing commands in the crontab. The server was running smoothly again, and the problem was now a safer one where the job queue has to be monitored for not growing indefinitely, searching for possible job parallelism and carefully creating new independent job queues.

jobq's People

Contributors

zerodeux avatar

Stargazers

raspbeguy avatar Simon ANDRE avatar Guillaume Dumoulin avatar Guillaume avatar tom bouillut avatar Danaël avatar  avatar Ferenc Erki avatar Ludo avatar Romain Sorrenti avatar Éric avatar Titouan Mathis avatar PatrX avatar  avatar reeslo avatar Cyrille SAVELIEF avatar Karimus Slamanux avatar Nicolas Bonnet avatar Guillaume MOREL avatar  avatar Cezar avatar Radu Topala avatar Thibault Duplessis avatar  avatar Pierre-Yves Dubreucq avatar Roman avatar

Watchers

Mathieu Lecarme avatar Gael Pasgrimaud avatar Johan Charpentier avatar guyzmo avatar Karimus Slamanux avatar James Cloos avatar  avatar  avatar  avatar  avatar  avatar _nirae avatar

jobq's Issues

bug when log files does not exists (when running in a container)

It just print some errors:

root@567d237b92f4:/home/user# jobq-profile -q dump
Use of uninitialized value $user in concatenation (.) or string at /usr/bin/jobq-profile line 60.
gzip: /var/log/user.log.gz: No such file or directory
Use of uninitialized value $user in concatenation (.) or string at /usr/bin/jobq-profile line 84.
No jobq event found for user '' and queue 'dump'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.