S
S
Sergey Kravchenko2016-05-12 10:55:07
PHP
Sergey Kravchenko, 2016-05-12 10:55:07

How to implement traffic distribution by percentage (Traffic Distribution System) for large loads?

It is necessary to implement traffic distribution: When going to example.com , a redirect to landing pages should occur:

  • landing1 - 50%
  • landing2 - 40%
  • landing3 - 10%

Percentages can change (stored in redis).
The partitioning algorithm itself is not complicated: we count each transition to example.com and scatter it among the necessary landing pages until the required percentages are approached.
Problems arise when testing this algorithm through Apache Bench with setting concurrent requests ( ab -n 100 -c 10 www.example.com ).
I looked at ready-made TDS solutions - they have a similar problem - there is no clear percentage distribution if you send competitive requests.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
lega, 2016-05-12
@lega

In nginx, you can make upstream to several nodes and set weights.
After changing the weights, you can simply reload the config.

A
Alexey, 2016-05-12
@alsopub

If the problem is specifically in the distribution by percentage of parallel requests, then as a variant of memcache increment, it also contains a pre-calculated list of urls, for your case this (you can mix it before storing it in memory):

http://landing1
http://landing1
http://landing1
http://landing1
http://landing1
http://landing2
http://landing2
http://landing2
http://landing2
http://landing3

and url selection by the remainder of the increment value divided by the number of urls.
As far as I remember, increment in memcache is an atomic operation and must guarantee its own sequential value for each request.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question