Как работает балансер на Апаче?
От: Аноним  
Дата: 25.11.13 17:26
Оценка:
Есть такая конфигурация:

<Proxy balancer://app1>
  Header add Set-Cookie "app1.ROUTEID=ROUTE.%{BALANCER_WORKER_ROUTE}e" env=BALANCER_ROUTE_CHANGED

  BalancerMember http://host1 route=route_0 
  BalancerMember http://host2 route=route_1 

  ProxySet lbmethod=byrequests stickysession=app1.ROUTEID
</Proxy>



В документации написано вот такое про stickysession:

When using cookie based stickyness, you need to configure the name of the cookie that contains the information about which back-end to use.
This is done via the stickysession attribute added to either ProxyPass or ProxySet.
The name of the cookie is case-sensitive. The balancer extracts the value of the cookie and looks for a member worker with route equal to that value.


И вот про такие 6 переменных:

At present there are 6 environment variables exported:

BALANCER_SESSION_STICKY
This is assigned the stickysession value used for the current request. It is the name of the cookie or request parameter used for sticky sessions

BALANCER_SESSION_ROUTE
This is assigned the route parsed from the current request.

BALANCER_NAME
This is assigned the name of the balancer used for the current request. The value is something like balancer://foo.

BALANCER_WORKER_NAME
This is assigned the name of the worker used for the current request. The value is something like http://hostA:1234.

BALANCER_WORKER_ROUTE
This is assigned the route of the worker that will be used for the current request.

BALANCER_ROUTE_CHANGED
This is set to 1 if the session route does not match the worker route (BALANCER_SESSION_ROUTE != BALANCER_WORKER_ROUTE) or the session does not yet have an established route. This can be used to determine when/if the client needs to be sent an updated route when sticky sessions are used.


Я в общих чертах понимаю, как это работает.
Но целостная картина в голове не складывается.

Кто-то может объяснить по шагам:
— что происходит при первом реквесте от клиента, когда еще никаких кук нет? Какие значения имеют указанные выше переменные? Как апач выбирает воркер, который будет обрабатывать реквест?
— что происходит при следующих реквестах, когда в реквесте уже есть кука app1.ROUTEID?
— Когда происходит вычисление переменной BALANCER_ROUTE_CHANGED? Из документации — "This is set to 1 if the session route does not match the worker route". В каком случае роут из сессии может не соответствовать рабочему роуту?
— Что происходит, если пришел реквест на определенный роут, а этот хост не отвечает?
— Что произойдет, если клиент изменит значение куки app1.ROUTEID?
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.