Question about allowing a percentage of traffic

1 view
Skip to first unread message

spacerobot

unread,
Mar 21, 2012, 2:44:26 PM3/21/12
to ng...@nginx.org
This is about traffic control, in the case we get slammed by heavier
traffic than expected we want to be able to gracefully only allow part
of the users' requests to come through.

In my current nginx config, I have a white list based on a
$http_x_user_id header in the request and only allow traffic from those
users.

The way I did it was a condition in the location / block:

if ( $http_x_user_id !~ (THE_WHITE_LIST_OF_IDs) ) {
return 503;
}

(We can control the white list dynamically and re-render the config with
Chef.)

What I also need to do is to allow a certain percentage of requests from
users whose id is not in the white list. For example, I need to be able
to allow 30% of users in addition to those in the white list to get
access. Based on my limited knowledge on nginx, I have no idea on what's
the best way to do it.

Any insights?

Thanks a lot.

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,224190,224190#msg-224190

_______________________________________________
nginx mailing list
ng...@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

Valentin V. Bartenev

unread,
Mar 21, 2012, 3:10:41 PM3/21/12
to ng...@nginx.org
On Wednesday 21 March 2012 22:44:26 spacerobot wrote:
> This is about traffic control, in the case we get slammed by heavier
> traffic than expected we want to be able to gracefully only allow part
> of the users' requests to come through.
>
> In my current nginx config, I have a white list based on a
> $http_x_user_id header in the request and only allow traffic from those
> users.
>
> The way I did it was a condition in the location / block:
>
> if ( $http_x_user_id !~ (THE_WHITE_LIST_OF_IDs) ) {
> return 503;
> }
>
> (We can control the white list dynamically and re-render the config with
> Chef.)
>
> What I also need to do is to allow a certain percentage of requests from
> users whose id is not in the white list. For example, I need to be able
> to allow 30% of users in addition to those in the white list to get
> access. Based on my limited knowledge on nginx, I have no idea on what's
> the best way to do it.
>
> Any insights?
>

Perhaps the split clients module will be suitable for you:

http://nginx.org/en/docs/http/ngx_http_split_clients_module.html

wbr, Valentin V. Bartenev

Alexandr Gomoliako

unread,
Mar 21, 2012, 3:14:17 PM3/21/12
to ng...@nginx.org
> What I also need to do is to allow a certain percentage of requests from
> users whose id is not in the white list. For example, I need to be able
> to allow 30% of users in addition to those in the white list to get
> access. Based on my limited knowledge on nginx, I have no idea on what's
> the best way to do it.
>
> Any insights?

Embedded perl can help.

Reply all
Reply to author
Forward
0 new messages