memory - Share variables between hosts with Go -
I have an application in Golong, and this will load basic data globally, so that the application responds faster Create and export a http interface to update the version while the user changes the database.
But I launch another server, and I use a proxy. There is a problem, when the user sends an update URL to the URL, it will load the traffic from any of the servers. Not others
utils.go:
Basic data map to package utilities [string] * MyModel func UpdateVar () {// some work} func PreLoadVar () { // preload data in original data} and main.Go
package main import ("codebase / utils") func main () {Utils. PreLoadVar ()} So is there any sharing between multiple hosts? Or can any worker help in this work?
Nsq.io is a good option, but if I think I want one more simpler. Thank you :)
Your global variable is a very simple form, which is known to be problematic when There are several ways to fix this problem: There are several ways to fix this problem:
- As suggested by Bill Nelson: Using your database as a central database And do not cache your data in your data.
- Open your cache externally with a simple key-value store, for example by using any one.
- Use a distributed cache such as.
If you have a lot of time on your hands, then may be use a message solution like NSQ to implement your distributed cache, but I I will advise against this - this is not an easy problem.
Comments
Post a Comment