Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workflow的http服务器接口如何做QPS限制? #1647

Open
TongxianYang opened this issue Nov 6, 2024 · 2 comments
Open

workflow的http服务器接口如何做QPS限制? #1647

TongxianYang opened this issue Nov 6, 2024 · 2 comments

Comments

@TongxianYang
Copy link

workflow的http服务器接口如何做QPS限制?

@Barenboim
Copy link
Contributor

Barenboim commented Nov 6, 2024

你好。我想了想,可以通过命名mailbox或命名conditional的方式,按照请求频率,定义一个timer的时间。例如,需要产生一个1000qps的server,就把timer定时为1ms。每次timer callback,通过WFTaskFactory::send_by_name()或WFTaskFactory::signal_by_name()的方式,叫醒一个任务。timer的callback大概可以这么写:

void timer_callback(WFTimerTask *timer)
{
    WFTaskFactory::send_by_name("1000_qps_list", nullptr, 1);
    series_of(timer)->push_back(WFTaskFactory::create_timer_task(0, 1000000, timer_callback));
}

如果当前没有mailbox接收消息,不会产生任何的影响。否则,每1ms最多执行一个任务。可以试试这个方法。

@Barenboim
Copy link
Contributor

send_by_name的时候,最后一个参数max需要传1,表示最多发给一个mailbox。这里就有很多调优空间了,例如,max参数可以传10,最多叫醒10个任务。然后根据send的返回值,我们可以动态的调整下一个timer的时间。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants