Skip to content

Commit

Permalink
feat(router): add optional query string affinity support
Browse files Browse the repository at this point in the history
To be enabled with extreme prejudice. Twelve-factor processes should be
stateless and share-nothing. Sticky sessions should not be used to cache
user data in memory. Use a backing store to persist session state.

Valid uses, however, do exist and are widespread: eg. see primus/primus#147

> HTTP implementations are expected to engage in connection management,
> which includes maintaining the state of current connections,
> establishing a new connection or reusing an existing connection,
> processing messages received on a connection, detecting connection
> failures, and closing each connection.
> <cite>[RFC 7230]</cite>

Many real time systems rely on detection of connection failures at the
application level. Without session affinity, detection of connection
failures stops at the load balancer and causes undesirable side-effects
for many implementations. For instance, the Google BrowserChannel implementation
that may have led @zag2art to deis#2060 relies on detection of connection
failures, as does socket.io

Care should be taken when using this setting in conjunction with a 3rd party
Layer-7 load balancer. At this time, Amazon's ELB and Rackspace's Cloud Load
Balancer, for instance, only support cookie-based affinity which must be
manually enabled. Many OSI Layer-4 load balancers, such as the Azure Load
Balancer and GCE Network Load Balancing, currently perform [RFC 2474] 5-tuple
"microflow" hashing by default.

[RFC 2474]: https://tools.ietf.org/html/rfc2474
[RFC 7230]: https://tools.ietf.org/html/rfc7230
  • Loading branch information
Alexander Wenzowski committed Feb 14, 2015
1 parent 3d59fef commit 419d046
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/customizing_deis/router_settings.rst
Expand Up @@ -37,6 +37,7 @@ setting description
/deis/controller/host host of the controller component (set by controller)
/deis/controller/port port of the controller component (set by controller)
/deis/domains/* domain configuration for applications (set by controller)
/deis/router/affinityArg nginx query string request argument to enable sticky routing (default: "")
/deis/router/bodySize nginx body size setting (default: 1m)
/deis/router/builder/timeout/connect proxy_connect_timeout for deis-builder (default: 10000). Unit in miliseconds
/deis/router/builder/timeout/read proxy_read_timeout for deis-builder (default: 1200000). Unit in miliseconds
Expand Down
2 changes: 2 additions & 0 deletions router/image/templates/nginx.conf
Expand Up @@ -129,6 +129,8 @@ http {
{{ $useSSL := or .deis_router_sslCert "false" }}
{{ $domains := .deis_domains }}{{ range $service := .deis_services }}{{ if $service.Nodes }}
upstream {{ Base $service.Key }} {
{{ $affinityArg := or .deis_router_affinityArg "" }}{{ if len($affinityArg) > 0 }}hash $arg_{{ $affinityArg }} consistent;
{{ end }}
{{ range $upstream := $service.Nodes }}server {{ $upstream.Value }};
{{ end }}
}
Expand Down

0 comments on commit 419d046

Please sign in to comment.