我需要一个运行尽可能快但不会减慢服务器速度的队列系统。
我有一个网络应用程序(php),可以转换不同的媒体(照片、视频等)。当有人想要转换文件时,转换命令会进入数据库。我需要一个可以以不会使我的服务器崩溃的方式运行命令的程序。
我需要以下内容:
- 始终在服务器上运行的东西。
-查看 postgres 数据库以获取新内容
- 前一个命令完成后,程序将前进到数据库中的下一个命令
- 当命令完成时,它会使用成功/失败和时间戳更新 postgres 表
-程序应该根据需要使用尽可能多的CPU,但不是优先级...我希望进程很快,但我不希望我的服务器爬行停止。
-程序需要能够限制不同的程序(因此,如果应用程序 1 正在运行并且有人为应用程序 2 提交...应用程序 2 不会运行,除非服务器可以处理它。)
有人知道任何可用的现有脚本或想法吗?我玩过 cpulimit 但这只是限制它不会让服务器在没有服务器负载时充分发挥其潜力。我已经尝试过 -nice -n 但这似乎不起作用。
I need a queque system that runs as fast as possible but doesn't slow down the server.
I have a web app (php) that converts different pieces of media (photos,video,etc). When someone wants to convert a file the command to convert goes into a database. I need a program that can run the commands in a way that will not crash my server.
I need the following:
-Something that always is running on the server.
-Looks at a postgres database for new content
-Program advances to the next command in the database once the previous command has finished
-When a command finishes it updates the postgres table with either success/failure and timestamp
-The program should use as much cpu as needed but not be the priority...I want the process to be fast but I don't want have my server crawl to a stop.
-Program needs to be able to limit different programs (so if app 1 is running and someone submits for app 2...app 2 doesn't run unless the server can handle it.)
Anyone know any existing scripts available or ideas? I have played with cpulimit but that just limits it doesn't let the server use its full potential when there is no server load. I have tried -nice -n but that doesn't seem to work.
发布评论
评论(2)
守护进程会做得很好。考虑客户端服务器模型 - 服务器将转换任务分派给子进程或调用 pthread_create 创建客户端线程来处理该任务。在 fork()/exec 或 pthread_create 时,您可以确定活动客户端的数量,从而确定系统上的负载。然后您可以相应地调整优先级。
这使您可以动态控制资源消耗。
我不明白为什么nice不能为你工作。在您的上下文中,“似乎不起作用”到底是什么意思?
A daemon will do well. Consider a client server model - the server dispatches conversion tasks to a child process or calls pthread_create to create a client thread to handle the task. At the time of fork()/exec or pthread_create you can determine the number of active clients, and hence the load on the system. Then you can adjust priority accordingly.
This gives you dynamic control of the resource consumption.
I fail to see why nice can not work for you. What exactly does "doesn't seem to work" mean in your context?
我编写了一个非常好的小系统,它会发送数十万封电子邮件(给网站的用户),该系统首先检查 CPU 平均负载。如果是< 2.0,继续,否则它会休眠几秒钟,然后重试。该 PHP 脚本是一个 bash 脚本,它在短暂的暂停后不断运行 PHP 脚本。
I wrote a very nice little system that would send hundreds of thousands of emails (to users of the website) that first checked the CPU Load average. If it was < 2.0, continue, otherwise it slept for a few seconds and then tried again. Wrapping that PHP script was a bash-script that just ran the PHP script continually, after a brief pause.