I want to run Folding@home client on my Ubuntu 8.10 box only when it's idle because of the program's heavy RAM consumption.
我想在我的Ubuntu 8.10机器上运行Folding @ home客户端,因为程序的RAM消耗很大。
By "idle" I mean the state when there's no user activity (keyboard, mouse or any other else). It's ok for other (probably heavy) processes to run at that time since F@H has the lowest CPU priority. The point is just to improve user experience and to do heavy work when the he is away.
“空闲”是指没有用户活动时的状态(键盘,鼠标或其他任何其他)。由于F @ H具有最低的CPU优先级,因此当时可以运行其他(可能很重)进程。关键在于改善用户体验并在他离开时做繁重的工作。
How to accomplish this?
怎么做到这一点?
7 个解决方案
#1
12
When the machine in question is a desktop, you could hook a start/stop script into the screensaver so that the process is stopped when the screensaver is inactive and vice versa.
当有问题的机器是桌面时,您可以将启动/停止脚本挂钩到屏幕保护程序中,以便在屏幕保护程序处于非活动状态时停止进程,反之亦然。
#2
4
It's fiddly to arrange for the process to only be present when the system is otherwise idle.
当系统处于空闲状态时,安排该过程仅存在是非常繁琐的。
Actually starting the program in those conditions isn't the hard bit. You have to arrange for the program to be cleanly shut down, and figure out how and when to do that.
实际上在那些条件下启动程序并不困难。你必须安排程序干净地关闭,并弄清楚如何以及何时这样做。
You have to be able to distinguish between that process's own CPU usage, and that of the other programs that might be running, so that you can tell whether the system is properly "idle".
您必须能够区分该进程自身的CPU使用率以及可能正在运行的其他程序的CPU使用情况,以便您可以判断系统是否正常“空闲”。
It's a lot easier for the process to only be scheduled when the system is otherwise idle. Just use the 'nice' command to launch the Folding@Home client.
只有在系统处于空闲状态时才能安排进程。只需使用'nice'命令启动Folding @ Home客户端即可。
However that won't solve the problem of insufficient RAM. If you've got swap space enabled, the system should be able to swap out any low priority processes such that they're not consuming and real resources, but beware of a big hit on disk I/O each time your Folding@Home client swaps in and out of RAM.
但是,这不能解决RAM不足的问题。如果您启用了交换空间,系统应该能够交换任何低优先级进程,以便它们不会消耗和实际资源,但要注意每次Folding @ Home客户端时磁盘I / O都会受到重创交换进出RAM。
p.s. RAM is very cheap at the moment...
附: RAM目前非常便宜......
p.p.s. see this article
p.p.s.看到这篇文章
#3
4
may be You need to set on idle task lowest priority via nice.
可能你需要通过nice设置空闲任务的最低优先级。
#4
2
Your going to want to look at a few things to determine 'idle' and also explore the sysinfo() call (the link points out the difference in the structure that it populates between various kernel versions).
您将要查看一些事情来确定'idle'并探索sysinfo()调用(该链接指出了它在各种内核版本之间填充的结构的差异)。
Linux does not manage memory in a typical way. Don't just look at loads, look at memory. In particular, /proc/meminfo has a wonderful line started with Committed_AS, which shows you how much memory the kernel has actually promised to other processes. Compare that with what you learned from sysinfo and you might realize that a one minute load average of 0.00 doesn't mean that its time to run some program that wants to allocate 256MB of memory, since the kernel may be really over-selling. Note, all values filled by sysinfo() are available via /proc, sysinfo() is just an easier way to get them.
Linux不以典型的方式管理内存。不要只看负载,看看记忆。特别是,/ proc / meminfo有一个很好的行,从Committed_AS开始,它向你展示了内核实际承诺给其他进程多少内存。将其与您从sysinfo中学到的内容进行比较,您可能会发现一分钟的平均负载为0.00并不意味着它需要运行一些想要分配256MB内存的程序,因为内核可能真的过度销售。注意,sysinfo()填充的所有值都可以通过/ proc获得,sysinfo()只是获取它们的一种更简单的方法。
You would also want to look at how much time each core has spent in IOWAIT since boot, which is an even stronger indicator of if you should run an I/O resource hog. Grab that info in /proc/stat, the first line contains the aggregate count of all CPU's. IOWAIT is in the 6'th field. Of course if you intend to set affinity to a single CPU, only that CPU would be of interest (its still the sixth field, in units of USER_HZ or typically in 100'ths of a second). Average that against btime, also found in /proc/stat.
您还需要了解自启动以来每个核心在IOWAIT中花费了多少时间,这是一个更强大的指标,表明您是否应该运行I / O资源。在/ proc / stat中获取该信息,第一行包含所有CPU的聚合计数。 IOWAIT在第6个领域。当然,如果你打算设置单个CPU的亲和力,那么只有那个CPU是有意义的(它仍然是第六个字段,以USER_HZ为单位,或者通常是100秒)。针对btime的平均值,也可以在/ proc / stat中找到。
In short, don't just look at load averages.
简而言之,不要只看负载平均值。
EDIT
编辑
You should not assume a lack of user input means idle.. cron jobs tend to run .. public services get taxed from time to time, etc. Idle remains your best guess based on reading the values (or perhaps more) that I listed above.
你不应该假设缺乏用户输入意味着空闲.. cron工作往往会运行..公共服务不时被征税等等。根据我上面列出的值(或者更多),空闲仍然是你最好的猜测。
EDIT 2
编辑2
Looking at the knob values in /proc/sys/vm also gives you a good indication of what the user thinks is idle, in particular swappiness. I realize your doing this only on your own box but this is an authoritative wiki and the question title is generic :)
查看/ proc / sys / vm中的旋钮值还可以很好地指示用户认为闲置的内容,特别是swappiness。我意识到你只在你自己的盒子上这样做,但这是一个权威的维基,问题标题是通用的:)
#5
1
The file /proc/loadavg has the systems current load. You can just write a bash script to check it, and if its low then run the command. Then you can add it to /etc/cron.d to run it periodically.
文件/ proc / loadavg具有系统当前负载。您可以只编写一个bash脚本来检查它,如果它低,则运行命令。然后,您可以将其添加到/etc/cron.d以定期运行它。
This file contains information about the system load. The first three numbers represent the number of active tasks on the system - processes that are actually running - averaged over the last 1, 5, and 15 minutes. The next entry shows the instantaneous current number of runnable tasks - processes that are currently scheduled to run rather than being blocked in a system call - and the total number of processes on the system. The final entry is the process ID of the process that most recently ran.
此文件包含有关系统负载的信息。前三个数字代表系统上活动任务的数量 - 实际运行的进程 - 在过去的1,5和15分钟内取平均值。下一个条目显示可运行任务的瞬时当前数量 - 当前计划运行而不是在系统调用中被阻止的进程 - 以及系统上的进程总数。最后一个条目是最近运行的进程的进程ID。
Example output:
输出示例:
0.55 0.47 0.43 1/210 12437
#6
1
If you're using Gnome then take look at this:
如果您正在使用Gnome,请查看以下内容:
http://live.gnome.org/GnomeScreensaver/FrequentlyAskedQuestions#head-ac43c8f33bc700a5e298e6a82ded0e8bb9b33043
#7
0
See this thread for a perl script that checks when the system is idle (through gnome screensaver).
You can run commands when idling starts and stops.
I'm using this with some scripts to change BOINC preferences when idling
(to give BOINC more memory and cpu usage).
请参阅此线程以获取perl脚本,该脚本检查系统何时处于空闲状态(通过gnome屏幕保护程序)。您可以在空闲开始和停止时运行命令。我正在使用一些脚本来在空闲时更改BOINC首选项(以便为BOINC提供更多内存和CPU使用)。
ubuntu论坛上的perl脚本
#1
12
When the machine in question is a desktop, you could hook a start/stop script into the screensaver so that the process is stopped when the screensaver is inactive and vice versa.
当有问题的机器是桌面时,您可以将启动/停止脚本挂钩到屏幕保护程序中,以便在屏幕保护程序处于非活动状态时停止进程,反之亦然。
#2
4
It's fiddly to arrange for the process to only be present when the system is otherwise idle.
当系统处于空闲状态时,安排该过程仅存在是非常繁琐的。
Actually starting the program in those conditions isn't the hard bit. You have to arrange for the program to be cleanly shut down, and figure out how and when to do that.
实际上在那些条件下启动程序并不困难。你必须安排程序干净地关闭,并弄清楚如何以及何时这样做。
You have to be able to distinguish between that process's own CPU usage, and that of the other programs that might be running, so that you can tell whether the system is properly "idle".
您必须能够区分该进程自身的CPU使用率以及可能正在运行的其他程序的CPU使用情况,以便您可以判断系统是否正常“空闲”。
It's a lot easier for the process to only be scheduled when the system is otherwise idle. Just use the 'nice' command to launch the Folding@Home client.
只有在系统处于空闲状态时才能安排进程。只需使用'nice'命令启动Folding @ Home客户端即可。
However that won't solve the problem of insufficient RAM. If you've got swap space enabled, the system should be able to swap out any low priority processes such that they're not consuming and real resources, but beware of a big hit on disk I/O each time your Folding@Home client swaps in and out of RAM.
但是,这不能解决RAM不足的问题。如果您启用了交换空间,系统应该能够交换任何低优先级进程,以便它们不会消耗和实际资源,但要注意每次Folding @ Home客户端时磁盘I / O都会受到重创交换进出RAM。
p.s. RAM is very cheap at the moment...
附: RAM目前非常便宜......
p.p.s. see this article
p.p.s.看到这篇文章
#3
4
may be You need to set on idle task lowest priority via nice.
可能你需要通过nice设置空闲任务的最低优先级。
#4
2
Your going to want to look at a few things to determine 'idle' and also explore the sysinfo() call (the link points out the difference in the structure that it populates between various kernel versions).
您将要查看一些事情来确定'idle'并探索sysinfo()调用(该链接指出了它在各种内核版本之间填充的结构的差异)。
Linux does not manage memory in a typical way. Don't just look at loads, look at memory. In particular, /proc/meminfo has a wonderful line started with Committed_AS, which shows you how much memory the kernel has actually promised to other processes. Compare that with what you learned from sysinfo and you might realize that a one minute load average of 0.00 doesn't mean that its time to run some program that wants to allocate 256MB of memory, since the kernel may be really over-selling. Note, all values filled by sysinfo() are available via /proc, sysinfo() is just an easier way to get them.
Linux不以典型的方式管理内存。不要只看负载,看看记忆。特别是,/ proc / meminfo有一个很好的行,从Committed_AS开始,它向你展示了内核实际承诺给其他进程多少内存。将其与您从sysinfo中学到的内容进行比较,您可能会发现一分钟的平均负载为0.00并不意味着它需要运行一些想要分配256MB内存的程序,因为内核可能真的过度销售。注意,sysinfo()填充的所有值都可以通过/ proc获得,sysinfo()只是获取它们的一种更简单的方法。
You would also want to look at how much time each core has spent in IOWAIT since boot, which is an even stronger indicator of if you should run an I/O resource hog. Grab that info in /proc/stat, the first line contains the aggregate count of all CPU's. IOWAIT is in the 6'th field. Of course if you intend to set affinity to a single CPU, only that CPU would be of interest (its still the sixth field, in units of USER_HZ or typically in 100'ths of a second). Average that against btime, also found in /proc/stat.
您还需要了解自启动以来每个核心在IOWAIT中花费了多少时间,这是一个更强大的指标,表明您是否应该运行I / O资源。在/ proc / stat中获取该信息,第一行包含所有CPU的聚合计数。 IOWAIT在第6个领域。当然,如果你打算设置单个CPU的亲和力,那么只有那个CPU是有意义的(它仍然是第六个字段,以USER_HZ为单位,或者通常是100秒)。针对btime的平均值,也可以在/ proc / stat中找到。
In short, don't just look at load averages.
简而言之,不要只看负载平均值。
EDIT
编辑
You should not assume a lack of user input means idle.. cron jobs tend to run .. public services get taxed from time to time, etc. Idle remains your best guess based on reading the values (or perhaps more) that I listed above.
你不应该假设缺乏用户输入意味着空闲.. cron工作往往会运行..公共服务不时被征税等等。根据我上面列出的值(或者更多),空闲仍然是你最好的猜测。
EDIT 2
编辑2
Looking at the knob values in /proc/sys/vm also gives you a good indication of what the user thinks is idle, in particular swappiness. I realize your doing this only on your own box but this is an authoritative wiki and the question title is generic :)
查看/ proc / sys / vm中的旋钮值还可以很好地指示用户认为闲置的内容,特别是swappiness。我意识到你只在你自己的盒子上这样做,但这是一个权威的维基,问题标题是通用的:)
#5
1
The file /proc/loadavg has the systems current load. You can just write a bash script to check it, and if its low then run the command. Then you can add it to /etc/cron.d to run it periodically.
文件/ proc / loadavg具有系统当前负载。您可以只编写一个bash脚本来检查它,如果它低,则运行命令。然后,您可以将其添加到/etc/cron.d以定期运行它。
This file contains information about the system load. The first three numbers represent the number of active tasks on the system - processes that are actually running - averaged over the last 1, 5, and 15 minutes. The next entry shows the instantaneous current number of runnable tasks - processes that are currently scheduled to run rather than being blocked in a system call - and the total number of processes on the system. The final entry is the process ID of the process that most recently ran.
此文件包含有关系统负载的信息。前三个数字代表系统上活动任务的数量 - 实际运行的进程 - 在过去的1,5和15分钟内取平均值。下一个条目显示可运行任务的瞬时当前数量 - 当前计划运行而不是在系统调用中被阻止的进程 - 以及系统上的进程总数。最后一个条目是最近运行的进程的进程ID。
Example output:
输出示例:
0.55 0.47 0.43 1/210 12437
#6
1
If you're using Gnome then take look at this:
如果您正在使用Gnome,请查看以下内容:
http://live.gnome.org/GnomeScreensaver/FrequentlyAskedQuestions#head-ac43c8f33bc700a5e298e6a82ded0e8bb9b33043
#7
0
See this thread for a perl script that checks when the system is idle (through gnome screensaver).
You can run commands when idling starts and stops.
I'm using this with some scripts to change BOINC preferences when idling
(to give BOINC more memory and cpu usage).
请参阅此线程以获取perl脚本,该脚本检查系统何时处于空闲状态(通过gnome屏幕保护程序)。您可以在空闲开始和停止时运行命令。我正在使用一些脚本来在空闲时更改BOINC首选项(以便为BOINC提供更多内存和CPU使用)。
ubuntu论坛上的perl脚本