标签: throttling

throttleShape 的参数是什么意思?

zio-streams 提供throttleShape

  /**
   * Delays the chunks of this stream according to the given bandwidth parameters using the token bucket
   * algorithm. Allows for burst in the processing of elements by allowing the token bucket to accumulate
   * tokens up to a `units + burst` threshold. The weight of each chunk is determined by the `costFn`
   * function.
   */
  final def throttleShape(units: Long, duration: Duration, burst: Long = 0)(
    costFn: Chunk[O] => Long
  ): ZStream[R with Clock, E, …
Run Code Online (Sandbox Code Playgroud)

scala throttling zio

4
推荐指数
1
解决办法
532
查看次数

如何根据方法参数应用速率限制

我正在使用 python 模块ratelimit来限制一个函数,该函数调用一个rest api,我需要根据请求的方法应用限制,例如每PUT/POST/DELETE10 秒 1 次,每GET1 秒 5 次,我怎样才能在不破坏功能一分为二?

from ratelimit import limits, sleep_and_retry

@sleep_and_retry
@limits(calls=1 if method != 'GET' else 5, period=10 if method != 'GET' else 1)
def callrest(method, url, data):
    ...
Run Code Online (Sandbox Code Playgroud)

是否有可能做到这一点?

python throttling rate-limiting python-3.x python-decorators

4
推荐指数
1
解决办法
1669
查看次数

Java限制

如何使用的组合ScheduledThreadPoolExecutor,ScheduledFutureExecutorCompletionService扼杀Callable接受一个可变参数的命令?在收到Callable命令的响应后,我需要Callable根据上述Callable命令的输出创建一个新命令.我还需要坚持每秒100次通话的门槛.

java throttling

3
推荐指数
1
解决办法
3122
查看次数

C#中的线程限制

我在VS2010中使用C#中的VB .NET 4创建了一个游戏.游戏为每个玩家创建一个线程,并运行玩家创建的LUA代码.

每个LUA代码都阻塞该线程,并且只应在线程终止时终止(LUA脚本应包含无限循环)

我希望限制CPU使用率,因为在使用100%CPU运行几个小时后计算机当前过热.

如何在没有控制权的情况下限制线程?我希望有一个线程管理器强制暂停/恢复,但那些已经过时了,我不想抛出异常,因为这将中止我正在执行的LUA代码.

有任何想法吗?

谢谢!

c# multithreading throttling visual-studio-2010

3
推荐指数
1
解决办法
2488
查看次数

Java thottling机制

更新:我在Java 1.6.34上,没有机会升级到Java 7.

我有一个场景,我只允许每分钟调用一次方法80次.它实际上是由第三方编写的服务API,如果你多次调用它,它会"关闭"(忽略调用)它的API:

public class WidgetService {
    // Can only call this method 80x/min, otherwise it
    // it just doesn't do anything
    public void doSomething(Fizz fizz);
}
Run Code Online (Sandbox Code Playgroud)

我想写一个ApiThrottler类,它有一个boolean canRun()方法可以告诉我的Java客户端是否doSomething(Fizz)可以调用该方法.(当然它总是被称为,但如果我们超过了我们的费率,就没有任何意义.)

所以我可以编写如下代码:

// 80x/min
ApiThrottler throttler = new ApiThrottler(80);

WidgetService widgetService = new DefaultWidgetService();

// Massive list of Fizzes
List<Fizz> fizzes = getFizzes();

for(Fizz fizz : fizzes)
    if(throttler.canRun())
        widgetService.doSomething(fizz);
Run Code Online (Sandbox Code Playgroud)

这不一定是API(ApiThrottler#canRun),但是我需要一个可靠/可靠的机制,它可以暂停/休眠直到WidgetService#doSomething(Fizz) 可以被调用.

这让我觉得我们正在进入使用多线程的领域,这让我觉得我们可以使用某种锁定机制和Java通知(wait()/ …

java multithreading mutex throttling locking

3
推荐指数
1
解决办法
2123
查看次数

是否可以创建一个节流功能,可以将另一个功能(也有参数)和时间延迟作为参数

因此,我已经编写了一个函数(基于下划线限制),用于不接受参数的函数,但我想使其足够通用,以传递具有可变数量参数的函数.这就是我所拥有的:

    (function () {

    var lastTime = new Date().getTime();

    function foo() {
        var newTime = new Date().getTime();
        var gap = newTime - lastTime; // Travels up scope chain to use parents lastTime.  Function has access to variables declared in the same scope
        console.log('foo called,  gap:' + gap);
        lastTime = newTime; // Updates lastTime
        //console.log(x);
        //x++;
    }

    var throttle = function(func, wait) {
        var result;
        var timeout = null; // flag updated through closure
        var previous = 0; // time last …
Run Code Online (Sandbox Code Playgroud)

javascript closures throttling

3
推荐指数
1
解决办法
3419
查看次数

在rx中有类似ThrottleOrMax的东西吗?

使用案例:我正在编写一个监视更改并自动保存的内容.我想要节流,以便我不会比每五秒钟更多地保存.如果有连续的变化流,我想每30秒保存一次.

无法在文档中找到observable.Throttle(mergeTime,maxTime),只能想到编写自己的丑陋方式,因此这个问题.

c# events throttling system.reactive

3
推荐指数
1
解决办法
220
查看次数

Gatling Throttle持有不工作

Gatling世界的新手,但是经验丰富的Loadrunner用户.我创建了一个示例模拟来运行两个场景,每个场景有10个用户,并希望运行10分钟.以下是我在setUp函数中的内容.但每次我运行模拟时,它只运行136秒.holdFor似乎没有生效.

setUp(
    scn.inject(rampUsers(10) over (10 seconds)),
    scen.inject(rampUsers(10) over (10 seconds))
)
.protocols(httpProtocol)
.throttle(
    reachRps(2) in (10 seconds),
    holdFor(10 minutes)
)
Run Code Online (Sandbox Code Playgroud)

我正在使用Gatling 2.2.2捆绑.

输出: Simulation computerdatabase.BasicSimulation completed in 136 seconds

throttling gatling

3
推荐指数
1
解决办法
3114
查看次数

如果 API 速率限制超过使用 WebApiThrottle - C# Web API,则阻止 API 请求 5 分钟

有一个非常好的库WebApiThrottle用于 Web API 中的 API 速率限制。
正如在 Wiki 页面上提到的,我可以根据 API 调用的授权令牌标头对 API 进行速率限制。
但是,如果此 api 速率限制超过,我如何在接下来的 5 分钟内阻止 api 调用?此外,在接下来的 5 分钟内的任何请求都不会重置超过时间的速率限制。

我检查了代码,但找不到此功能。如果有人可以建议,还有其他方法吗?

c# api throttling rate-limiting asp.net-web-api

3
推荐指数
1
解决办法
5566
查看次数

React 事件侦听器,但油门未被移除

我的代码看起来像这样:

componentDidMount() {
    window.addEventListener('resize', this.resize);
}

componentWillUnmount() {
    window.removeEventListener('resize', this.resize);
}

resize = () => this.forceUpdate();
Run Code Online (Sandbox Code Playgroud)

这工作正常。但后来我尝试添加一个油门以获得更好的性能

componentDidMount() {
    window.addEventListener('resize', _.throttle(this.resize, 200));
}

componentWillUnmount() {
    window.removeEventListener('resize', this.resize);
}

resize = () => this.forceUpdate();
Run Code Online (Sandbox Code Playgroud)

但是当我在不同的视图中调整屏幕大小时,我收到此错误警告:

Warning: forceUpdate(...): Can only update a mounted or mounting component. This usually means you called forceUpdate() on an unmounted component. This is a no-op. Please check the code for the component.
Run Code Online (Sandbox Code Playgroud)

这意味着我没有正确删除侦听器。如何删除带有节流阀的侦听器?或者我应该把油门放在别的地方?

我尝试更新componentWillUnmount喜欢这样:

componentWillUnmount() {
    window.removeEventListener('resize', _.throttle(this.resize, 200));
}
Run Code Online (Sandbox Code Playgroud)

但这也不起作用。

有任何想法吗

javascript throttling addeventlistener reactjs

3
推荐指数
1
解决办法
966
查看次数