-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #234 from bnb-chain/develop
release: prepare for v0.0.5
- Loading branch information
Showing
84 changed files
with
1,723 additions
and
435 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package gopool | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/panjf2000/ants/v2" | ||
) | ||
|
||
var ( | ||
// Init a instance pool when importing ants. | ||
defaultPool, _ = ants.NewPool(ants.DefaultAntsPoolSize, ants.WithExpiryDuration(10*time.Second)) | ||
) | ||
|
||
// Submit submits a task to pool. | ||
func Submit(task func()) error { | ||
return defaultPool.Submit(task) | ||
} | ||
|
||
// Running returns the number of the currently running goroutines. | ||
func Running() int { | ||
return defaultPool.Running() | ||
} | ||
|
||
// Cap returns the capacity of this default pool. | ||
func Cap() int { | ||
return defaultPool.Cap() | ||
} | ||
|
||
// Free returns the available goroutines to work. | ||
func Free() int { | ||
return defaultPool.Free() | ||
} | ||
|
||
// Release Closes the default pool. | ||
func Release() { | ||
defaultPool.Release() | ||
} | ||
|
||
// Reboot reboots the default pool. | ||
func Reboot() { | ||
defaultPool.Reboot() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package metrics | ||
|
||
import ( | ||
"net/http" | ||
"sync" | ||
) | ||
|
||
func NewRunOnceHttpMux(mux *http.ServeMux) *RunOnceHttpMux { | ||
return &RunOnceHttpMux{ | ||
ServeMux: mux, | ||
once: &sync.Once{}, | ||
} | ||
} | ||
|
||
type RunOnceHttpMux struct { | ||
*http.ServeMux | ||
once *sync.Once | ||
} | ||
|
||
func (mux *RunOnceHttpMux) ListenAndServe(addr string) error { | ||
var err error | ||
mux.once.Do(func() { | ||
err = http.ListenAndServe(addr, mux.ServeMux) | ||
}) | ||
|
||
return err | ||
} | ||
|
||
type MetricsServer interface { | ||
Start() error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package pprof | ||
|
||
import ( | ||
"net/http/pprof" | ||
|
||
"github.com/bnb-chain/zkbnb/common/metrics" | ||
) | ||
|
||
var _ metrics.MetricsServer = (*PProfServer)(nil) | ||
|
||
func NewPProfServer(srv *metrics.RunOnceHttpMux, addr string) metrics.MetricsServer { | ||
srv.Handle("/debug/pprof/goroutine", pprof.Handler("goroutine")) | ||
srv.Handle("/debug/pprof/threadcreate", pprof.Handler("threadcreate")) | ||
srv.Handle("/debug/pprof/heap", pprof.Handler("heap")) | ||
srv.Handle("/debug/pprof/allocs", pprof.Handler("allocs")) | ||
srv.Handle("/debug/pprof/block", pprof.Handler("block")) | ||
srv.Handle("/debug/pprof/mutex", pprof.Handler("mutex")) | ||
return &PProfServer{ | ||
srv: srv, | ||
addr: addr, | ||
} | ||
} | ||
|
||
type PProfServer struct { | ||
srv *metrics.RunOnceHttpMux | ||
addr string | ||
} | ||
|
||
func (server *PProfServer) Start() error { | ||
return server.srv.ListenAndServe(server.addr) | ||
} |
Oops, something went wrong.