如何获取 gearman 中特定类型的排队作业数量?

发布于 2024-09-11 22:35:08 字数 232 浏览 4 评论 0原文

我有很多 gearman 客户发送了一份作业,比如 job1。

$client = new GearmanClient();
$client->addServer();
$client->doBackground('job1', 'workload');

处理此作业需要 10 秒钟。 我想跟踪在任何给定时间有多少“job1”工作正在等待工人处理。我怎样才能做到这一点?

I have a number of gearman clients sending a job, say job1.

$client = new GearmanClient();
$client->addServer();
$client->doBackground('job1', 'workload');

It takes, say 10 seconds to process this job.
I want to track how many 'job1' jobs are waiting for a worker to work on them at any given time. How can I do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

始于初秋 2024-09-18 22:35:08

为了快速检查,我使用了这个 bash 单行代码:

(echo status ; sleep 0.1) | netcat 127.0.0.1 4730

这将打开与本地主机上运行的 gearman 实例的连接,并发送状态查询。其中包含该实例上作业的名称和数量。然后可以使用grep/awk/wc等处理该信息以进行报告和警报。

我还对显示所有连接的工作人员的 workers 查询执行相同的操作。

(echo workers ; sleep 0.1) | netcat 127.0.0.1 4730

睡眠是为了保持连接打开足够长的时间以进行回复。

管理命令的完整列表以及输出的含义位于 http://gearman.org/protocol/ 。只需搜索“管理协议”即可。

For quick checking, I use this bash one-liner:

(echo status ; sleep 0.1) | netcat 127.0.0.1 4730

This opens a connection to a gearman instance running on localhost, and sends the status query. This contains the name and number of jobs on that instance. The information can then be processed with grep/awk/wc etc. for reporting and alerting.

I also do the same with the workers query which shows all connected workers.

(echo workers ; sleep 0.1) | netcat 127.0.0.1 4730

The sleep is to keep the connection open long enough for the reply.

The full list of administrative commands, and what the output means is at http://gearman.org/protocol/. Just search for "Administrative Protocol".

将军与妓 2024-09-18 22:35:08

为了扩展 d5ve 的答案,添加一个 -w 参数来“超时”你的 netcat 连接,否则你永远不会回到命令提示符。

$ (echo status ; sleep 0.1) | sudo netcat 127.0.0.1 4730 -w 1

To expand on d5ve's answer, add a -w parameter to "time out" your netcat connection, otherwise you never get back to a command prompt.

$ (echo status ; sleep 0.1) | sudo netcat 127.0.0.1 4730 -w 1
丑疤怪 2024-09-18 22:35:08
telnet localhost 4730
status

worker_name total_queue currently_running number_of_workers
job1         1          1                 9
telnet localhost 4730
status

worker_name total_queue currently_running number_of_workers
job1         1          1                 9
故事未完 2024-09-18 22:35:08

我使用 gearman_top,它是 mod 的一部分-齿轮工

网站的输出示例:

+-----------------------+--------+-------+-------+---------+
| Name                  | Worker | Avail | Queue | Running |
+-----------------------+--------+-------+-------+---------+
| check_results         | 1      | 1     | 0     | 0       |
| host                  | 3      | 3     | 0     | 0       |
| service               | 3      | 3     | 0     | 0       |
| eventhandler          | 3      | 3     | 0     | 0       |
| servicegroup_jmx4perl | 3      | 3     | 0     | 0       |
| hostgroup_japan       | 3      | 3     | 0     | 0       |
+-----------------------+--------+-------+-------+---------+

I use gearman_top, which is part of mod-gearman.

Example output from the website:

+-----------------------+--------+-------+-------+---------+
| Name                  | Worker | Avail | Queue | Running |
+-----------------------+--------+-------+-------+---------+
| check_results         | 1      | 1     | 0     | 0       |
| host                  | 3      | 3     | 0     | 0       |
| service               | 3      | 3     | 0     | 0       |
| eventhandler          | 3      | 3     | 0     | 0       |
| servicegroup_jmx4perl | 3      | 3     | 0     | 0       |
| hostgroup_japan       | 3      | 3     | 0     | 0       |
+-----------------------+--------+-------+-------+---------+
乖乖公主 2024-09-18 22:35:08

在 Ubuntu 18.04 上,我默认使用 gearman 包安装了 gearadmin 二进制文件。

gearadmin --help
可以使用 gearadmin --status 代替 netcat 替代方案:

gearadmin --status
queue1    334     10      10

还有一个衬垫:
<代码>同时:;执行 gearadmin --status;睡觉1;完成

On Ubuntu 18.04 I have the gearadmin binary installed by default with the gearman package.

gearadmin --help
gearadmin --status can be used instead of the netcat alternative:

gearadmin --status
queue1    334     10      10

And a one liner:
while :; do gearadmin --status; sleep 1; done

妥活 2024-09-18 22:35:08

看起来没有任何直接的方法可以获取此信息。

这里有几个选项。首先,您是否可以在创建作业句柄时获取作业句柄 (搜索“谈到检查状态”),您可以将它们存储在某个中心位置并从任何客户端查询它们。

其次,您可以将 Gearman 服务器设置为使用持久队列,并且然后自己对队列运行查询。这可能是两个选项中更简单、更干净的一个。

It doesn't look like there are any immediate ways to get this information.

Here are a few options. First, if you can grab job handles as you create them (search for "Speaking of checking the status"), you can store them away in some central place and query about them from any client.

Second, you can set your Gearman server to use persistent queues, and then run a query against the queue yourself. This might be the easier and cleaner of the two options.

静若繁花 2024-09-18 22:35:08

Gearmand有一个telnet接口可以查询。 (协议的具体细节可以在 gearman 网站上找到 - http://gearman.org/?id=协议

我在这里使用此代码作为滚动我自己的代码的起点。
https://github.com/liorbk/php/blob/master/GearmanTelnet.php
(这段代码本身就非常好,您应该能够直接使用它)

这是一个不太漂亮的解决方案,但直到有人改进 gearman 管理界面,以便您可以直接通过 PHP 进行对话或为其编写一个插件,您靠你自己

Gearmand has a telnet interface you can query. (the exact details of the protocol can be found on the gearman website - http://gearman.org/?id=protocol )

I used this code here as a starting point for rolling my own.
https://github.com/liorbk/php/blob/master/GearmanTelnet.php
(this code is perfectly good by itself and you should be able to drop use it out of the box)

It's a less than pretty solution but until someone improves gearman admin interface so you can talk directly via PHP or writes a plugin for it, you are on your own

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文