Linux学习之task-spooler是一个Unix批处理系统

本文介绍了如何使用Linux的task-spooler工具来解决多人编译时抢占资源的问题,提供了一种有效的批处理系统方法。
摘要由CSDN通过智能技术生成

解决 多人编译 抢占资源问题, 使用 linux task spooler 工具.

task spooler is a Unix batch system where the tasks spooled run one after the other. The amount of
jobs to run at once can be set at any time. Each user in each system has his own job queue. The 
tasks are run in the correct context (that of enqueue) from any shell/process, and its output/results
can be easily watched. It is very useful when you know that your commands depend on a lot of RAM, 
a lot of disk use, give a lot of output, or for whatever reason it's better not to run them all at
the same time, while you want to keep your resources busy for maximum benfit. Its interface allows
using it easily in scripts.
task spooler 是一个简单的批处理程序, 他可以实现简单的队列功能, 当你有多个任务(假设3个任务)需要执行的时候,
每个任务都是比较消耗内存, 消耗cpu资源, 消耗IO资源的任务(类似的编译android镜像, repo更新android代码).
如果你让这3个任务同时执行,可能每个任务执行的都很慢,每个任务都在抢占系统资源(抢占cpu,抢占内存,抢占IO).
这个时候你可以使用 task spooler 命令来包装你的命令, 可以设置队列中的执行个数是1(默认是1, 也可以设置大于1,
服务器性能好的可以设置大于1,但是设置的太大也就没啥用了), 
这样这3个任务会依次排队的执行, 这样的好处就是每个任务都能得到最大的系统资源, 3个任务顺序的整个执行下来说不定
执行时间还会小于3个同时执行的时间呢.


当一个服务器(尤其是研发的编译服务器)多个人使用的时候,这个每个人都在抢占系统资源,这个时候使用这个工具就能很好的
达到资源的合理利用了.每个人都能最大的使用系统资源.

tsp 工具  可以实现 多人共享一个队列. 这个队列默认只能同时执行一个任务, 当然也可以设置同时执行多个任务.
tsp 工具 执行命令的时候是克隆当时的环境变量的,例如你编译安卓  执行过了 source 执行过了了lunch, 这时候你只需要 tsp make就能编译了.

执行很简单的, 就是在你的命令前 加上 tsp  

例如更新代码:  tsp  repo sync -cdj4 --no-tags   
例如编译: tsp make -j64  (tsp命令同时会帮你保存命令的输出到文件的, 这样就可以保存编译日志了,事后可以查看)

$ tsp  (这个是默认执行tsp命令, 如果队列没有任何任务,就是输出如下的样子)
ID   State      E-Level  Times    [run=0/1] Command &>Output 

$ tsp -h
usage: tsp [action] [-ngfmdE] [-L <lab>] [-D <id>] [cmd...]
Actions:
  -K       kill the task spooler server
  -C       clear the list of finished jobs
  -l       show the job list (default action)
  -S [num] get/set the number of max simultaneous jobs of the server.
  -t [id]  "tail -n 10 -f" the output of the job. Last run if not specified.
  -c [id]  like -t, but shows all the lines. Last run if not specified.
  -p [id]  show the pid of the job. Last run if not specified.
  -o [id]  show the output file. Of last job run, if not specified.
  -i [id]  show job information. Of last job run, if not specified.
  -s [id]  show the job state. Of the last added, if not specified.
  -r [id]  remove a job. The last added, if not specified.
  -w [id]  wait for a job. The last added, if not specified.
  -k [id]  send SIGTERM to the job process group. The last run, if not specified.
  -u [id]  put that job first. The last added, if not specified.
  -U <id-id>  swap two jobs in the queue.
  -B       in case of full queue on the server, quit (2) instead of waiting.
  -h       show this help
  -V       show the program version
Options 
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值