Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App Engine Flex Session Affinity #242

Open
wesoos opened this issue Aug 8, 2018 · 10 comments
Open

App Engine Flex Session Affinity #242

wesoos opened this issue Aug 8, 2018 · 10 comments

Comments

@wesoos
Copy link

wesoos commented Aug 8, 2018

Hello, I believe the app engine flex uses the cloud load balancers underneath, correct? When will we be able to configure the load balancer to use session affinity? You can do it for a normal cloud load balancer in front of compute engine instances, why not app engine?

Using the gcp-datastore-sessions variable does not work in all cases, especially Vaadin apps where session affinity is required.

There are a lot of people wanting this feature!

@Petikoch
Copy link

+1 from me

@gregw
Copy link
Contributor

gregw commented May 22, 2019

Note also that if session affinity is available, we can add a more efficient memory cache for sessions in each instance that will reduce the load on the shared session store and improve semantics for co-located requests. The image can easily be modified to take advantage of affinity.

@Petikoch
Copy link

Just dicovered this
https://cloud.google.com/blog/products/application-development/introducing-websockets-support-for-app-engine-flexible-environment
and this
https://cloud.google.com/appengine/docs/flexible/java/using-websockets-and-session-affinity
(see bottom of this page)

It looks like in order to offer WebSockets on the flex environment "they" implemented session-affinity

app.yaml:

network:
  session_affinity: true

@gregw
Copy link
Contributor

gregw commented May 22, 2019

@Petikoch Thanks for that - I'll test that out (probably next week) and if it works will see what session options should be turned on in the image to best make use of that.

@Petikoch
Copy link

Excellent, thanks a lot @gregw

@gregw
Copy link
Contributor

gregw commented May 23, 2019

I've done some testing with the session_affinity and it appears to work fine. It does not trigger off the JSESSION_ID, rather it set's it's own GCLB cookie.
The normal default in memory session should work OK with this setup, but if the affinity is not entirely sticky (if the GCLB cookie is lost, a node shuts down etc.) then session data will be lost. So a better setup would be to have an in memory cache fronting the gcloud datastore. This can be achieved with the following in your app.yaml:

env_variables:
    JETTY_MODULES_ENABLE: session-cache-hash,gcp-datastore,session-store-gcloud

This will avoid hitting the datastore on every request, sessions will only be written when dirty. I can see in my tests that objects in the sessions are coming back with the same value and same hashcode (so they have not been serialized deserialized)!

I will add this to the doco!

gregw added a commit that referenced this issue May 23, 2019
Signed-off-by: Greg Wilkins <[email protected]>
@gregw
Copy link
Contributor

gregw commented May 23, 2019

Pull request #260 documents this

@menulis
Copy link

menulis commented Aug 8, 2019

Should it be enough to set session_affinity to true in app.yaml to enable session affinity or is there a specific Jetty module that also needs to be enabled with JETTY_MODULES_ENABLE? Does the GCP Load Balancer needs to be set up too? Documentation does not say anything about that and I cannot see any additional cookies (like the GCLB cookie mentioned by @gregw before) set in the response after having enabled session_affinity. Or is it just websockets for which App Engine flex supports session affinity?

@gregw
Copy link
Contributor

gregw commented Aug 12, 2019

If you set session_affinity to true, you will get session affinity implemented by the Google load balancer using its own additional cookie. This will work with no changes to Jetty.

However, one of the main points of session affinity is to allow efficient session management from an in memory session cache, so if you have affinity, you can turn this on with the session-cache-hash module. It's not necessary, but it's kind of the point!

@menulis
Copy link

menulis commented Aug 12, 2019

Thanks for the clarification, @gregw. This was exactly how I thought. However, as I wrote, basic session infinity does not seem to work in my case. I set session_affinity under network: in app.yaml, but do not see any additional (GCLB or other) cookies added to the HTTP responses. This is why I thought that I may be missing one or another Jetty module or the Load Balancer has to be configured in some way (I do not have configured it at all, so as I understand, all App Engine Flex defaults should be functioning).

gregw added a commit that referenced this issue Oct 3, 2019
* Issue #242 Session Affinity

Signed-off-by: Greg Wilkins <[email protected]>

* fixed typo

Signed-off-by: Greg Wilkins <[email protected]>

* updates from review

Signed-off-by: Greg Wilkins <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants