diff --git a/nsqd/http.go b/nsqd/http.go index 309332336..7fa2a10e5 100644 --- a/nsqd/http.go +++ b/nsqd/http.go @@ -13,6 +13,7 @@ import ( "os" "reflect" "runtime" + "runtime/debug" "strconv" "strings" "time" @@ -85,6 +86,7 @@ func newHTTPServer(nsqd *NSQD, tlsEnabled bool, tlsRequired bool) *httpServer { router.Handler("GET", "/debug/pprof/goroutine", pprof.Handler("goroutine")) router.Handler("GET", "/debug/pprof/block", pprof.Handler("block")) router.Handle("PUT", "/debug/setblockrate", http_api.Decorate(setBlockRateHandler, log, http_api.PlainText)) + router.Handle("POST", "/debug/freememory", http_api.Decorate(freeMemory, log, http_api.PlainText)) router.Handler("GET", "/debug/pprof/threadcreate", pprof.Handler("threadcreate")) return s @@ -99,6 +101,11 @@ func setBlockRateHandler(w http.ResponseWriter, req *http.Request, ps httprouter return nil, nil } +func freeMemory(w http.ResponseWriter, req *http.Request, ps httprouter.Params) (interface{}, error) { + debug.FreeOSMemory() + return nil, nil +} + func (s *httpServer) ServeHTTP(w http.ResponseWriter, req *http.Request) { if !s.tlsEnabled && s.tlsRequired { resp := fmt.Sprintf(`{"message": "TLS_REQUIRED", "https_port": %d}`,