问题
If I would like to deploy my application using Play Framework 2.x to multiple servers, what are the things I need to care about?
If I am using (built-in) sessions, will it be available to all the nodes since they are stored in browser side?
How can I share variables application-wide except for storing them in the database?
回答1:
When putting a Play application in production to multiple server nodes, you should check following steps:
- Ensure the application secret (that encrypts and signs the
session
cookie) IS THE SAME on every node, as you won't be able to which node will send the HTTP response. - Ensure that you did not use the built in cache system (ehcache) to store user specific information (as the cache is stored in server's memory).
That's all...
So to answer your other points:
- If you're using (built-in) sessions, information stored in the
session
cookie will be available to every server node (as it comes from the client). Just remember that a cookie is limited to 4kb in some old browsers (IE6), so be carefull about the quantity of information you put in the session. If you want to share other application wide variables:
if the information is user specific, you can also store them on the
session
, or in another cookie. For instance if you want to save current user's theme:response().setCookie("theme", "blue");
. Then you can retrieve the stored information withHttp.Request.current().cookies.get("theme")
. You can have a deeper look into play sessions and cookie.If you want to share other variables across multiple nodes, you'll have to use distributed cache solutions like memcached or, your database like you suggested.
If not already done, you should have a look into how to deploy play to production
来源:https://stackoverflow.com/questions/29624216/what-should-i-do-if-i-want-to-deploy-play-framework-app-to-multiple-servers