我的笔记本装上ubuntu后,只能使用4小时不到,但使用xp可以将近7小时。所以看到这个标题的时候就激动的记录了下来。。
原文:http://hutuworm.blogspot.com/2009/04/linux.html
1. Linux Kernel 2.6.21 开始支持 Tickless(此前的内核默认设置为 1000Hz timer tick),于是系统空闲时不再无故骚扰 CPU,可以节省大量能耗。Fedora 7+ 以及目前的 Ubuntu Linux 发行版都含有 Tickless 特性,而 RHEL 则要到版本 6 才会随新版本内核正式支持该特性(预计 2010年上市)。检查你的 Linux 系统是否支持 Tickless: watch --interval=1 cat /proc/interrupts ,若 timer 中断值并非以 1000 为步进单位增加,则说明该内核支持 Tickless。
2. 编译内核(make menuconfig):
- 启用 Tickless: Processor type and features -> [*] Tickless System (Dynamic Ticks)
- 启 用 CONFIG_USB_SUSPEND: Device Drivers -> USB support -> [*] USB selective suspend/resume and wakeup (自动禁用 UHCI USB,可以节省约 1 watt)
3. PowerTOP 可以找出计算机闲置时哪些进程耗电最多。(Kernel Hacking -> [*] Collect kernel timers statistics) 详见: http://www.lesswatts.org/projects/powertop/
4. 启用 power aware CPU scheduler(Scheduler Power Saving Mode): echo 1 > /sys/devices/system/cpu/sched_mc_power_savings
5. RHEL 5.3 支持 Intel Core i7 (Nehalem) 的电源管理功能。
6. 启用 irqbalance 服务,既可以提升性能,又可以降低能耗。irqbalance 用于优化中断分配,它会自动收集系统数据以分析使用模式,并依据系统负载状况将工作状态置于 Performance mode 或 Power-save mode。处于 Performance mode 时,irqbalance 会将中断尽可能均匀地分发给各个 CPU core,以充分利用 CPU 多核,提升性能。处于 Power-save mode 时,irqbalance 会将中断集中分配给第一个 CPU,以保证其它空闲 CPU 的睡眠时间,降低能耗。(详见:http://www.irqbalance.org/documentation.php )
7. 禁用 pcscd,该进程会阻碍 USB 子系统进入 Power-save mode。
8. 将 VM dirty writeback time 延长至 15 秒: echo 1500 > /proc/sys/vm/dirty_writeback_centisecs
9. 启用 noatime 文件系统选项: mount -o remount,noatime / (noatime 禁止更新 atime,可以节省大量 I/O,但为了避免 atime 相关应用程序出现问题,建议启用 relatime 代之: mount -o remount,relatime / ,relatime 自 Kernel 2.6.29 起为默认设置。)
10. 禁止 hal 轮询你的 cdrom: hal-disable-polling --device /dev/cdrom
* 关于 Linux 节能的更多信息,请看: http://www.lesswatts.org
来自向东:http://www.xiangdong.org/blog/post/1743/
文章太长,不作过多介绍,反正,文章的头部就说明了大概的意思。。。
原文如下:
写了一个简单的队列任务处理。多进程任务,异步任务可能会用到这个(主要是命令行应用)
比如,任务的某个一个环节速度十分不稳定,可能执行几秒,也可能执行几分钟,
我就可以把那个环节包括前面的部分扔进队列,多跑几个进程,同时往队列里面写。
然后后面比较快的环节只跑一个处理任务就OK了。让整体速度达到更好的效果。
write.php: 将任务写入队列
PHP代码
- <?php
-
-
-
-
- function mt($identifier='default')
- {
- return sprintf("%.6f.%s",strtok(microtime(),' ')+strtok(''),$identifier);
- }
-
- while(1)
- {
- if(count(glob('./queue/*.identifier'))>=10)
- {
- sleep(1);
- continue;
- }
- $url = 'www.'.time().'.com';
- echo "$url\r\n";
- $fp = fopen('./queue/'.mt('identifier'),'w');
- fwrite($fp,$url);
- fclose($fp);
- sleep(1);
- }
- ?>
read.php:
PHP代码
- <?php
-
-
-
-
- while(1)
- {
- if($queue = glob('./queue/*.identifier'))
- {
- $q = array_shift($queue);
- $url = file_get_contents($q);
- echo $url."\r\n";
- unlink($q);
- }
- sleep(1);
- }
- ?>
相关的资料:双向队列
baidu和google上没有查到PHP双向队列的资料,搜索到java的双向队列定义如下:双向队列(双端队列)就像是一个队列,但是你可以在任何一端添加或移除元素。
而双端队列是一种数据结构,定义如下:
A deque is a data structure consisting of a list of items, on which the following operations are possible.
* push(D,X) -- insert item X on the rear end of deque D.
* pop(D) -- remove the front item from the deque D and return it.
* inject(D,X) -- insert item X on the front end of deque D.
* eject(D) -- remove the rear item from the deque D and return it.
Write routines to support the deque that take O(1) time per operation.
翻译:双端队列(deque)是由一些项的表组成的数据结构,对该数据结构可以进行下列操作:
push(D,X) 将项X 插入到双端队列D的前端
pop(D) 从双端队列D中删除前端项并将其返回
inject(D,X) 将项X插入到双端队列D的尾端
eject(D) 从双端队列D中删除尾端项并将其返回
编写支持双端队伍的例程,每种操作均花费O(1)时间
百度百科:(deque,全名double-ended queue)是一种具有队列和栈的性质的数据结构。双端队列中的元素可以从两端弹出,其限定插入和删除操作在表的两端进行。
转贴一个使用Php数组函数实现该功能的代码:
PHP代码
- <?php
-
- class DoubleEndedQueue1 {
- var $queue = array();
- function add($var){
- return array_push($this->queue, $var);
- }
- function frontRemove(){
- return array_shift($this->queue);
- }
- function rearRemove(){
- return array_pop($this->queue);
- }
- }
-
-
- class DoubleEndedQueue2 {
- var $queue = array();
- function remove(){
- return array_pop($this->queue);
- }
- function frontAdd($var){
- return array_unshift($this->queue, $var);
- }
- function rearAdd($var){
- return array_push($this->queue, $var);
- }
- }
-
-
- $q = new DoubleEndedQueue1;
- $q->add('aaa');
- $q->add('bbb');
- $q->add('ccc');
- $q->add('ddd');
-
- echo $q->frontRemove();
- echo "<br>";
- echo $q->rearRemove();
- echo "<br>";
- print_r($q->queue);
- ?>
array_push -- 将一个或多个单元压入数组的末尾(入栈)
array_unshift -- 在数组开头插入一个或多个单元
array_pop -- 将数组最后一个单元弹出(出栈)
array_shift -- 将数组开头的单元移出数组
// 来自 PHP5 in Practice (U.S.)Elliott III & Jonathan D.Eisenhamer
PHP代码
- <?php
-
-
- function &queue_initialize() {
-
- $new = array();
- return $new;
- }
-
- function queue_destroy(&$queue) {
-
- unset($queue);
- }
-
- function queue_enqueue(&$queue, $value) {
-
-
- $queue[] = $value;
- }
-
- function queue_dequeue(&$queue) {
-
- return array_shift($queue);
- }
-
- function queue_peek(&$queue) {
-
-
- return $queue[0];
- }
-
- function queue_size(&$queue) {
-
- return count($queue);
- }
-
- function queue_rotate(&$queue) {
-
- $queue[] = array_shift($queue);
- }
-
-
- $myqueue =& queue_initialize();
- queue_enqueue($myqueue, 'Opal');
- queue_enqueue($myqueue, 'Dolphin');
- queue_enqueue($myqueue, 'Pelican');
-
-
- echo '<p>Queue size is: ', queue_size($myqueue), '</p>';
-
- echo '<p>Front of the queue is: ', queue_peek($myqueue), '</p>';
-
- queue_rotate($myqueue);
-
- echo '<p>Removed the element at the front of the queue: ',
- queue_dequeue($myqueue), '</p>';
-
- queue_destroy($myqueue);
- ?>