Skip to content

Commit 92a5549

Browse files
author
Alexander Wenzowski
committed
feat(router): add optional query string affinity support
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 #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
1 parent 1a16562 commit 92a5549

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

docs/customizing_deis/router_settings.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ setting description
3737
/deis/controller/host host of the controller component (set by controller)
3838
/deis/controller/port port of the controller component (set by controller)
3939
/deis/domains/* domain configuration for applications (set by controller)
40+
/deis/router/affinityArg for requests with the indicated query string variable, hash its contents to perform session affinity (default: undefined)
4041
/deis/router/bodySize nginx body size setting (default: 1m)
4142
/deis/router/builder/timeout/connect proxy_connect_timeout for deis-builder (default: 10000). Unit in miliseconds
4243
/deis/router/builder/timeout/read proxy_read_timeout for deis-builder (default: 1200000). Unit in miliseconds

router/image/templates/nginx.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,11 @@ http {
140140

141141
## start service definitions for each application
142142
{{ $useSSL := or .deis_router_sslCert "false" }}
143+
{{ $affinityArg := .deis_router_affinityArg }}
143144
{{ $domains := .deis_domains }}{{ range $service := .deis_services }}{{ if $service.Nodes }}
144145
upstream {{ Base $service.Key }} {
146+
{{ if $affinityArg }}hash $arg_{{ $affinityArg }} consistent;
147+
{{ end }}
145148
{{ range $upstream := $service.Nodes }}server {{ $upstream.Value }};
146149
{{ end }}
147150
}

0 commit comments

Comments
 (0)