Skip to content

Commit

Permalink
Merge branch 'master' into issues/issue16
Browse files Browse the repository at this point in the history
* master:
  mxqd: Limit call rate of killall_over_time() to max. every 5 minutes
  mx_util: Add mx_within_rate_limit_or_return(sec, ret)
  README.md: Add links to sources
  • Loading branch information
mariux committed Oct 23, 2015
2 parents 4fe5b6e + 1f1c51a commit bdd2d5a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# mxq
MXQ - mariux64 job scheduling system

## Sources
### Main git repository

https://github.molgen.mpg.de/mariux64/mxq

### github.com clone

https://github.com/mariux/mxq

## Installation
### Install using `GNU make`
```
Expand Down
14 changes: 14 additions & 0 deletions mx_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <string.h>
#include <stdio.h>
#include <sched.h>
#include <unistd.h>
#include <sys/time.h>

#include "mx_log.h"

Expand Down Expand Up @@ -71,6 +73,18 @@ static inline void __mx_fclose(FILE **ptr) {
#undef mx_streq_nocase
#define mx_streq_nocase(a, b) (strcasecmp((a), (b)) == 0)

#define mx_within_rate_limit_or_return(sec, ret) \
do {\
static struct timeval _sleep = {0};\
struct timeval _now;\
struct timeval _delta;\
gettimeofday(&_now, NULL);\
timersub(&_now, &_sleep, &_delta);\
if (_delta.tv_sec < (sec))\
return (ret);\
_sleep = _now;\
} while(0)

int mx_strbeginswith(char *str, const char *start, char **endptr);
int mx_stribeginswith(char *str, const char *start, char **endptr);
int mx_strbeginswithany(char *str, char **starts, char **endptr);
Expand Down
6 changes: 5 additions & 1 deletion mxqd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,11 @@ int killall_over_time(struct mxq_server *server)

assert(server);

/* limit killing to every >= 5 minutes */
mx_within_rate_limit_or_return(5*60, 1);

mx_log_info("killall_over_time: Sending signals to all jobs running longer than requested.");

gettimeofday(&now, NULL);

for (user=server->users; user; user=user->next) {
Expand Down Expand Up @@ -1909,7 +1914,6 @@ int main(int argc, char *argv[])
killallcancelled(&server, SIGTERM, 0);
killallcancelled(&server, SIGINT, 0);
killall_over_time(&server);
killall_over_time(&server);

mx_log_info("jobs_running=%lu global_sigint_cnt=%d global_sigterm_cnt=%d : Exiting. Wating for jobs to finish. Sleeping for a while.",
server.jobs_running, global_sigint_cnt, global_sigterm_cnt);
Expand Down

0 comments on commit bdd2d5a

Please sign in to comment.