Summer Sale! All accounts are 50% off this week.

frsiswanto's avatar

How to disable throttle or rate limiter ?

Hi. I need help from you guys. I want to disable rate limiter because I want to make some load test, and I already make comment on Kernel.php:

        'api' => [
            // 'throttle:120,1',
            'bindings',
        ],

but my load test still have response 429 from ThrottleRequests class. What should I do next? Thanks.

0 likes
5 replies
Sergiu17's avatar
use Illuminate\Foundation\Testing\WithoutMiddleware;

class ExampleTestClass extends TestCase
{
    use WithoutMiddleware;

    public function exampleTestMethod()
    {
        $this->withoutMiddleware();

        // your test 
    }
}
1 like
frsiswanto's avatar

Thanks for the answer but I don't need create new test. My web api (using laravel 5.6) already run and used by my customer, but sometimes CPU utilization on the server is very high. That's why I need to run some load test against the api, and I also already create load test script using visual studio 2015. Script test is working but the api keep response 429 at heavy request. To save time, my first attempt is just disable all throttle from api and let web server (IIS) handle it. Please help to disable it.

frsiswanto's avatar
frsiswanto
OP
Best Answer
Level 1

When there is pressure is up, the solution will come in any way. This is my solution so far:

-1. Create new entry in app.php:

'app_config' => json_decode(env("APP_CONFIG", "{}"), TRUE),

-2. Create new middleware base on ThrottleRequests, name it as you like, mine is like this:

namespace App\Http\Middleware;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Closure;
class NoThrottle extends ThrottleRequests
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @param  int|string  $maxAttempts
     * @param  float|int  $decayMinutes
     * @return mixed
     * @throws \Illuminate\Http\Exceptions\ThrottleRequestsException
     */
    public function handle($request, Closure $next, $maxAttempts = 60, $decayMinutes = 1)
    {
        if (config("app.app_config")["nothrottle"] ?? false) {
            $response = $next($request);
            return $this->addHeaders(
                $response, $maxAttempts,
                $maxAttempts
            );
        }
        return parent::handle($request, $next, $maxAttempts, $decayMinutes);
    }
}

-3. Update $routeMiddleware inside Kernel.php:

        //'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
        'throttle' => \App\Http\Middleware\NoThrottle::class,

Usage: To disable throttle, add new entry in .env:

APP_CONFIG={"nothrottle":true}

This solution is now enough for me to do some load test, I hope someone wants to improve it.

sharad9838's avatar

Simply go to config->cartalyst.sentinel.php Comment

'checkpoints' => [ /*'throttle', // 'activation' */ ], Or Increase the thresholds limit

Like 'ip' => [ 'interval' => 900,

        'thresholds' => 500,
    ],

    'user' => [
        'interval' => 900,

        'thresholds' => 500,
    ],
harddy's avatar

I tried to comment throttle:60:1 and 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,

It's working for me

Please or to participate in this conversation.