I have an application write in golang,and it will load the basic data to global var,so make the application response fast,and export a http interface to update the var when user make changes to the database.
But i deploy another server,and used proxy.There comes a problem,when user send http request to the update url,it will load traffic to one of the servers.So that server update this var,but others not.
such as utils.go:
package utils
var BasicDatas map[string]*MyModel
func UpdateVar(){
// do some work
}
func PreLoadVar(){
// preload data to basicDatas
}
and the main.go
package main
import(
"codebase/utils"
)
func main(){
utils.PreLoadVar()
}
so if there anyway to share the var between multi hosts?Or any libiary can help do this work?
Nsq.io seem a good choice,but i want to seek a more simple one if there is. thanks:)
Your global variable is a very simple form of caching, which is well known to be problematic when you are running your application on multiple servers. There are several ways to fix this problem:
If you have too much time on your hands you could use a messaging solution like nsq to implement your own distributed cache, but I would advise against it - this is not an easy problem.