add clear cache
This commit is contained in:
parent
b0b783f7c8
commit
d8ac7b9b2e
@ -144,7 +144,8 @@ func NewPM(confFp string) (*ProxyManager, error) {
|
|||||||
pm.Cache = NewQueueMap()
|
pm.Cache = NewQueueMap()
|
||||||
pm.applyWeight()
|
pm.applyWeight()
|
||||||
// go pm.keepClearingCache()
|
// go pm.keepClearingCache()
|
||||||
go pm.dynamicWeightLoader()
|
pm.dynamicWeightLoader()
|
||||||
|
pm.listenToClearCache()
|
||||||
return &pm, nil
|
return &pm, nil
|
||||||
}
|
}
|
||||||
func (pm *ProxyManager) DescribeLoadBalanceMode() string {
|
func (pm *ProxyManager) DescribeLoadBalanceMode() string {
|
||||||
@ -227,24 +228,16 @@ func (pm *ProxyManager) Get(addr string) (string, bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// func (pm *ProxyManager) ClearCache() {
|
func (pm *ProxyManager) listenToClearCache() {
|
||||||
// // fmt.Println("clearing cache")
|
sigs := make(chan os.Signal, 1)
|
||||||
// pm.mux.Lock()
|
signal.Notify(sigs, syscall.SIGUSR2, syscall.SIGTERM)
|
||||||
// pm.Cache = New()
|
go func() {
|
||||||
// pm.mux.Unlock()
|
<-sigs
|
||||||
// // fmt.Println("after:", pm.Cache)
|
pm.mux.Lock()
|
||||||
// }
|
pm.Cache = NewQueueMap()
|
||||||
|
pm.mux.Unlock()
|
||||||
// func (pm *ProxyManager) keepClearingCache() {
|
}()
|
||||||
// interval := pm.CacheCleanInterval
|
}
|
||||||
// if interval <= 0 {
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// for {
|
|
||||||
// time.Sleep(time.Duration(interval) * time.Second)
|
|
||||||
// pm.ClearCache()
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
func (pm *ProxyManager) dynamicWeightLoader() {
|
func (pm *ProxyManager) dynamicWeightLoader() {
|
||||||
sigs := make(chan os.Signal, 1)
|
sigs := make(chan os.Signal, 1)
|
||||||
|
|||||||
@ -195,6 +195,13 @@ class OManager:
|
|||||||
# else:
|
# else:
|
||||||
#print("weight not changed, weights:", new_weights)
|
#print("weight not changed, weights:", new_weights)
|
||||||
|
|
||||||
|
def clear_cache(self):
|
||||||
|
for pid in self.pids:
|
||||||
|
try:
|
||||||
|
os.kill(pid, signal.SIGUSR2)
|
||||||
|
except:
|
||||||
|
print("error clear cache of", pid)
|
||||||
|
|
||||||
async def run_cmd(self, cmd):
|
async def run_cmd(self, cmd):
|
||||||
while True:
|
while True:
|
||||||
print("Manager trying to start go")
|
print("Manager trying to start go")
|
||||||
|
|||||||
6
test.py
6
test.py
@ -95,6 +95,11 @@ class RemoveInstatnceHandler(tornado.web.RequestHandler):
|
|||||||
self.write("remove all")
|
self.write("remove all")
|
||||||
|
|
||||||
|
|
||||||
|
class ClearCacheInstatnceHandler(tornado.web.RequestHandler):
|
||||||
|
def get(self):
|
||||||
|
om.clear_cache()
|
||||||
|
|
||||||
|
|
||||||
def make_app():
|
def make_app():
|
||||||
return tornado.web.Application([
|
return tornado.web.Application([
|
||||||
(r"/", MainHandler),
|
(r"/", MainHandler),
|
||||||
@ -103,6 +108,7 @@ def make_app():
|
|||||||
(r"/start", StartInstatnceHandler),
|
(r"/start", StartInstatnceHandler),
|
||||||
(r"/stop", StopInstatnceHandler),
|
(r"/stop", StopInstatnceHandler),
|
||||||
(r"/remove", RemoveInstatnceHandler),
|
(r"/remove", RemoveInstatnceHandler),
|
||||||
|
(r"/clear_cache", ClearCacheInstatnceHandler),
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user