PHP扩展php-affinity.zip

时间:2022-08-08 07:58:23
【文件属性】:

文件名称:PHP扩展php-affinity.zip

文件大小:102KB

文件格式:ZIP

更新时间:2022-08-08 07:58:23

开源项目

Php-affinity 通过设置cpu亲和性,可以将进程绑定到一个cpu核心上。一般在如下场景我们可能会希望修改进程的cpu亲和性: 频繁的并行运算 线程可伸缩性测试(通过增加cpu核心数量模拟线性扩展) 运行时间敏感的,决定性的进程向nginx,swoole等开源软件,都提供了设置cpu亲和性的方法。nginx官方建议worker数量等同于cpu核心数量也是为了将一个进程绑定到一个cpu核心上,同时避免进程切换带来的开销。Php本身并没有提供设置cpu亲和性的函数,我们可以通过两种方式实现: 调用系统命令,修改当前进程cpu亲和性 编写php扩展,封装系统调用。php-affinity是使用c编写的php扩展,项目地址:https://github.com/huyanping/php-affinity    /**                      * set CPU affinity                      *                      * @param $cpu_id                      * @return bool                      */                     functionsetaffinity($cpu_id){                         $num= getcpucores();                         if($cpu_id>= $num){                             returnfalse;                         }                         $set= system_call($cpu_id);                         if($set=== -1){                             returnfalse;                         }                                               returntrue;                     }                                           /**                      * get CPU affinity                      *                      * @return bool                      */                     functiongetaffinity(){                         $cpu_id= system_call();                         if($cpu_id=== -1){                             returnfalse;                         }                         return$cpu_id;                     }                                                                 /**                      * get number of CPU                      *                      * @return bool                      */                     functiongetcpucores(){                         $nums= system_call();                         if($nums=== -1){                             returnfalse;                         }                         return$nums;                     }提供了如下三个函数:setaffinity – 设置cpu亲和性getaffinity – 获取cpu亲和性getcpucores – 获取cpu核心数量API 如下:参考文献:https://zh.wikipedia.org/wiki/处理器亲和性http://www.ibm.com/developerworks/cn/linux/l-affinity.htmlhttp://www.cnblogs.com/LubinLew/p/cpu_affinity.html 标签:phpaffinity


【文件预览】:
JCPullToSelect-master
----JCPullToSelect-master()
--------JCPullToSelect-master()
--------JCPullToSelect-masterTests()
--------JCPullToSelect-master.xcodeproj()
--------JCPullToSelect-masterUITests()
----JCPullToSelect()
--------JCBallLayer.m(5KB)
--------JCBallLayer.h(609B)
--------JCHeader.m(13KB)
--------JCPullToSelect.h(2KB)
--------UIScrollView+JCPullToSelect.m(1KB)
--------JCFooter.h(412B)
--------JCFooter.m(5KB)
--------JCHeader.h(898B)
--------JCPullToSelect.bundle()
--------UIScrollView+JCPullToSelect.h(389B)
----LICENSE(1KB)
----README.md(1KB)
----JCPullToSelect.podspec(555B)

网友评论