简体   繁体   中英

Is global variables are shared between instances? Ruby on rails + Unicorn + Nginx

We have a one RoR application where we used one global variable.

When we tried to HTTP requests from multiple browsers, for fraction of seconds it's getting nil , again after few seconds refresh it get filled with value.

Not sure what's the happening here, is Global variable shared between multiple HTTP requests, and due to latency creating over there?

It will more helpful if I get more detailed information on Global variables.

again after few seconds refresh it get filled with value.

It probably has nothing to do with the fact that your waiting a few seconds. If anything when you refreshed the browser, nginx forwarded your request to a different Ruby process than the request before.

Global variables are only global within the same process - If you are running 2 Ruby processes, and set a global variable in the first the second won't see this.

If you really want to share data between multiple processes, using a database is the standard way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM