Welcome! Log In Create A New Profile

Advanced

session persistence for non browser based services

session persistence for non browser based services
November 25, 2015 05:14AM
Hi,

I have non browser based RESTFul services(coming from another proxy server). I am using NGINX for load balancing.
For stateless requests, I am using round robin method.
Need to implement stateful requests.

Cannot use ip hash, as all requests come from same proxy server(no separate IPs).
Sticky session is based on cookies, not sure if cookies will work for non browser based requests.

for my sequence of requests I have a server defined session which I can use for routing to the same server for my stateful requests.

Please advice the best way to do it.
Re: session persistence for non browser based services
November 25, 2015 05:46AM
This might help: http://dgtool.blogspot.nl/2013/02/nginx-as-sticky-balancer-for-ha-using.html

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: session persistence for non browser based services
November 25, 2015 07:01AM
Thank you. Really good info. But not sure if cookies will work for non browser based requests.

Anyone else has any other approach?
Re: session persistence for non browser based services
November 25, 2015 07:19AM
Your best bet is to make a flow diagram and mark in there what you want to happen under which circumstances, after that we can figure out which options are available. For example there is the option $realip_remote_addr which I think is mappable or at the least usable in Lua.

To loadbalance a service you either need to make the service identifiable from inside the service or from the resource using the service.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: session persistence for non browser based services
November 25, 2015 08:49AM
Http requests from users from
different ip address--> Goes to a client Server-->Through an API provided by MyProject, requests are sent to Myproject Server through a load balancer(ip address is same for all requests).

Myproject have three different servers. For stateless using round robin method og NGINX, 3 servers processes the request.

For stateful, all requests should go to only 1 instance of MyProject server. Issue here is I cannot use ip hash and for cookies method mentioned in the url http://dgtool.blogspot.nl/2013/02/nginx-as-sticky-balancer-for-ha-using.html
not sure if it will work since my requests are not from a browser, but a server.
Re: session persistence for non browser based services
November 25, 2015 09:36AM
Hmmm,

--Flow--:
1. Clients
2. Client server with nginx (loadbalancer)
3. Myproject servers (3x)

Do you know if a request is stateful/stateless between 1 and 2 ? (when it arrives at 2)
(if you can detect the state you can use 2 upstreams)

If this flow is not correct please edit because your description is not really clear to me. Ea. where is your API located? between 1 and 2? if so what 'edit' methods do you have at API level (can you add a header)?

If your API is not intelligent enough you may have to flip it with the loadbalancer and use 3 API's (behind nginx).

If the API is not too complicated you might consider rewriting it in Lua and embed it in nginx.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: session persistence for non browser based services
November 26, 2015 04:32AM
-Flow--:
1. Clients
2. Client server(not maintained by us)

3. Client requests (REST API service calls)
4.Load balancer
5, Myproject servers (3x) responds to services.

MyProject server creates a session id and sends it back in case of stateful calls, back to the client server and this id is carried in subsequent request-response.

This workflow is in place and working till we have 1 server. In case of 3 servers, we need to make step 4 and 5 sticky, so that all requests for a session id goes to the same server.

step 4 and 5 are under our control.



Edited 1 time(s). Last edit at 11/26/2015 04:38AM by niharika.jain@validsoft.com.
Re: session persistence for non browser based services
November 26, 2015 05:04AM
The easiest would be at 2 to add a header with client information, when that header arrives at your systems you can easily do things with it. Would it be possible to do anything at flow point 2 ?

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: session persistence for non browser based services
November 26, 2015 08:38AM
niharika.jain@validsoft.com Wrote:
-------------------------------------------------------
> MyProject server creates a session id and sends it back in case of
> stateful calls, back to the client server and this id is carried in
> subsequent request-response.
>
> This workflow is in place and working till we have 1 server. In case
> of 3 servers, we need to make step 4 and 5 sticky, so that all
> requests for a session id goes to the same server.

For the sake of conversation, what if you always create a session id with additional information about the state type and use that to determine what is going where? (at step 4)

ea. request/?data=xxxx&sessionID=yyyyy&state=zzzz

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: session persistence for non browser based services
November 26, 2015 08:40AM
yes, we already have a program generated session id which is passed in request-response to maintain session. we want to use this session id for sticky sessions in nginx opensource load balancer.
Re: session persistence for non browser based services
November 26, 2015 08:51AM
niharika.jain@validsoft.com Wrote:
-------------------------------------------------------
> yes, we already have a program generated session id which is passed in
> request-response to maintain session. we want to use this session id
> for sticky sessions in nginx opensource load balancer.

I meant to use this for non-sticky sessions as well, maybe use it as a hash for the balance algorithm.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: session persistence for non browser based services
November 26, 2015 09:55AM
Thanks. I read about it. Are you aware of the configuration required for the same. Standard way is

upstream backend {
hash $request_uri consistent;

server backend1.example.com;
server backend2.example.com;
}

my parameter is say sessionID. simply mapping it to hash $sessionID may not work. How do we define and configure in NGINX that this sessionID parameter is the one in my 3 servers and to get the value from my servers.
Re: session persistence for non browser based services
November 26, 2015 12:09PM
First you map the argument (sessionID) in to a variable,
https://www.axivo.com/threads/how-do-i-map-a-location-pattern-in-nginx.59/
https://www.ruby-forum.com/topic/4410004
And then you can use it in hash.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: session persistence for non browser based services
December 01, 2015 09:37AM
Thank you for all inputs. Right now I am trying the sticky module in nginx open source.

Has anyone used sticky module? I am not able to understand the configuration present at

https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng

which mentions:

Installation
You'll need to re-compile Nginx from source to include this module. Modify your compile of Nginx by adding the following directive (modified to suit your path of course):
./configure ... --add-module=/absolute/path/to/nginx-sticky-module-ng
make
make install

-------------------------------------------
1.what exactly I need to add in config file and under which directive?
2.Where do I place the sticky module files?
3. On a trial basis I am setting uo nginx on my windows 7 machine, but couldnt find sticky module for windows. Can i use the normal sticky module?
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 300
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready