Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Unified Diff: appengine/gaemiddleware/context.go

Issue 2594463002: Don't allcoate a new math/rand every request. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/gaemiddleware/context.go
diff --git a/appengine/gaemiddleware/context.go b/appengine/gaemiddleware/context.go
index d4215448f58a997c4e2efd5add2ab7e2c58e5c42..f55e232f2e0511736bff7bb52cf100a19497c6c3 100644
--- a/appengine/gaemiddleware/context.go
+++ b/appengine/gaemiddleware/context.go
@@ -17,6 +17,7 @@ import (
"github.com/luci/luci-go/common/config"
"github.com/luci/luci-go/common/data/caching/cacheContext"
"github.com/luci/luci-go/common/data/caching/proccache"
+ "github.com/luci/luci-go/common/data/rand/mathrand"
"github.com/luci/luci-go/common/logging"
"github.com/luci/luci-go/server/auth"
@@ -61,10 +62,14 @@ var (
// globalTsMonState holds state related to time series monitoring.
globalTsMonState = &tsmon.State{}
+
+ // globalMathRand is a global "math/rand" instance.
Vadim Sh. 2016/12/20 00:56:37 actually, nit: add a comment stating that this obj
dnj 2016/12/20 00:58:48 Done.
+ globalMathRand = mathrand.Get(context.Background())
)
// WithProd installs the set of standard production AppEngine services:
// * github.com/luci/luci-go/common/logging (set default level to debug).
+// * github.com/luci/luci-go/common/data/rand/mathrand.
// * github.com/luci/gae/impl/prod (production appengine services)
// * github.com/luci/luci-go/appengine/gaeauth/client (appengine urlfetch transport)
// * github.com/luci/luci-go/server/proccache (in process memory cache)
@@ -75,6 +80,7 @@ var (
func WithProd(c context.Context, req *http.Request) context.Context {
// These are needed to use fetchCachedSettings.
c = logging.SetLevel(c, logging.Debug)
+ c = mathrand.SetRand(c, globalMathRand)
c = prod.Use(c, req)
c = settings.Use(c, globalSettings)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698