简体   繁体   English

PHP proc_nice是否将Apache线程保留为新的优先级设置?

[英]Does PHP proc_nice leave Apache threads at new priority setting?

When executing proc_nice(), is it actually nice'ing Apache's thread? 当执行proc_nice()时,实际上对Apache的线程好吗?

If so, and if the current user (non-super user) can't renice to its original priority is killing the Apache thread appropriate (apache_child_terminate) on an Apache 2.0x server? 如果是这样,并且当前用户(非超级用户)是否无法忠于其原始优先级,那将杀死Apache 2.0x服务器上适当的Apache线程(apache_child_terminate)?

The issue is that I am trying to limit the impact of an app that allows the user to run Ad-Hack queries. 问题是我试图限制允许用户运行Ad-Hack查询的应用程序的影响。 The Queries can be massive and the resultant transform on the data requires a lot of Memory and CPU. 查询可能非常庞大,对数据的最终转换需要大量的内存和CPU。

I've already re-written the process to be more stream based - helping with the memory consumption, but I would also like the process to run a lower priority. 我已经重新编写了流程,使其更加基于流-帮助减少了内存消耗,但是我也希望流程运行优先级较低。 However I can't leave the Apache thread in low priority as we have a lot of high-priority web services running on this same box. 但是,我不能将Apache线程的优先级设置为低,因为我们有许多高优先级的Web服务都在同一盒子上运行。

TIA TIA

In that kind of situation, a solution if often to not do that kind of heavy work within the Apache processes, but either : 在这种情况下,一种解决方案通常是不在Apache进程中执行此类繁重的工作,但是:

  • run an external PHP process, using something like shell_exec , for instance -- this is if you must work in synchronous mode (ie, if you cannot execute the task a couple of minutes later) 例如,使用shell_exec类的程序运行外部PHP进程-这是如果您必须以同步模式工作(即,如果几分钟后无法执行任务)
  • push the task to a FIFO system, and immediatly return a message to the user saying "your task will be processed soon" 将任务推送到FIFO系统,并立即向用户返回一条消息,指出“您的任务将很快得到处理”
    • and have some other process (launched via a crontab every minute, for instance) check that FIFO queue 并让其他进程(例如,每分钟通过crontab启动)检查FIFO队列
    • and do the processing it there is something in the queue 并进行处理,队列中有东西
    • That process, itself, can run in low priority mode. 该过程本身可以在低优先级模式下运行。


As often as possible, especially if the heavy calculations take some time, I would go for the second solution : 尽可能多地使用,特别是如果繁重的计算需要花费一些时间,我将寻求第二种解决方案:

  • It allows users to get some feedback immediatly : "the server has received your request, and will process it soon" 它允许用户立即获得一些反馈:“服务器已收到您的请求,并将尽快处理它”
  • It doesn't keep Apaches's processes "working" for long : the heavy stuff is done by other processes 它不能使Apaches的进程长期保持“正常工作”:繁重的工作由其他进程完成
  • If, one day, you need such an amount of processing power that one server is not enough anymore, this kind of system will be easier to scale : just add a second server that'll pick from the same FIFO queue 如果有一天,您需要如此之多的处理能力,以至于一台服务器不再足够,那么这种系统将更易于扩展:只需添加另一台将从同一FIFO队列中选择的服务器即可
  • If your server is really too loaded, you can stop processing from the queue, at least for some time, so the load can get better -- for instance, this can be usefull if your critical web-services are used a lot in a specific time-frame. 如果服务器的负载确实过大,则可以至少从队列中停止处理一段时间,这样负载才能变得更好-例如,如果关键Web服务在特定环境中大量使用,这可能很有用。大体时间。


Another (nice-looking, but I haven't tried it yet) solution would be to use some kind of tool like, for instance, Gearman : 另一个(看起来不错,但我还没有尝试过)解决方案是使用某种工具,例如Gearman

Gearman provides a generic application framework to farm out work to other machines or processes that are better suited to do the work. Gearman提供了一个通用的应用程序框架,可以将工作分配到更适合执行该工作的其他机器或进程。
It allows you to do work in parallel, to load balance processing, and to call functions between languages. 它允许您并行执行工作,进行负载平衡处理以及在语言之间调用函数。
It can be used in a variety of applications, from high-availability web sites to the transport of database replication events. 它可用于各种应用程序,从高可用性网站到数据库复制事件的传输。
In other words, it is the nervous system for how distributed processing communicates. 换句话说,它是分布式处理如何通信的神经系统。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM