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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package gaemiddleware 5 package gaemiddleware
6 6
7 import ( 7 import (
8 "net/http" 8 "net/http"
9 9
10 "golang.org/x/net/context" 10 "golang.org/x/net/context"
11 "google.golang.org/appengine" 11 "google.golang.org/appengine"
12 12
13 "github.com/luci/gae/filter/dscache" 13 "github.com/luci/gae/filter/dscache"
14 "github.com/luci/gae/impl/prod" 14 "github.com/luci/gae/impl/prod"
15 "github.com/luci/gae/service/urlfetch" 15 "github.com/luci/gae/service/urlfetch"
16 16
17 "github.com/luci/luci-go/common/config" 17 "github.com/luci/luci-go/common/config"
18 "github.com/luci/luci-go/common/data/caching/cacheContext" 18 "github.com/luci/luci-go/common/data/caching/cacheContext"
19 "github.com/luci/luci-go/common/data/caching/proccache" 19 "github.com/luci/luci-go/common/data/caching/proccache"
20 "github.com/luci/luci-go/common/data/rand/mathrand"
20 "github.com/luci/luci-go/common/logging" 21 "github.com/luci/luci-go/common/logging"
21 22
22 "github.com/luci/luci-go/server/auth" 23 "github.com/luci/luci-go/server/auth"
23 "github.com/luci/luci-go/server/auth/authdb" 24 "github.com/luci/luci-go/server/auth/authdb"
24 "github.com/luci/luci-go/server/middleware" 25 "github.com/luci/luci-go/server/middleware"
25 "github.com/luci/luci-go/server/router" 26 "github.com/luci/luci-go/server/router"
26 "github.com/luci/luci-go/server/settings" 27 "github.com/luci/luci-go/server/settings"
27 28
28 "github.com/luci/luci-go/appengine/gaeauth/client" 29 "github.com/luci/luci-go/appengine/gaeauth/client"
29 "github.com/luci/luci-go/appengine/gaeauth/server" 30 "github.com/luci/luci-go/appengine/gaeauth/server"
(...skipping 24 matching lines...) Expand all
54 globalAuthConfig = auth.Config{ 55 globalAuthConfig = auth.Config{
55 DBProvider: authdb.NewDBCache(server.GetAuthDB), 56 DBProvider: authdb.NewDBCache(server.GetAuthDB),
56 Signer: gaesigner.Signer{}, 57 Signer: gaesigner.Signer{},
57 AccessTokenProvider: client.GetAccessToken, 58 AccessTokenProvider: client.GetAccessToken,
58 AnonymousTransport: urlfetch.Get, 59 AnonymousTransport: urlfetch.Get,
59 GlobalCache: &server.Memcache{Namespace: "__luciauth__"} , 60 GlobalCache: &server.Memcache{Namespace: "__luciauth__"} ,
60 } 61 }
61 62
62 // globalTsMonState holds state related to time series monitoring. 63 // globalTsMonState holds state related to time series monitoring.
63 globalTsMonState = &tsmon.State{} 64 globalTsMonState = &tsmon.State{}
65
66 // 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.
67 globalMathRand = mathrand.Get(context.Background())
64 ) 68 )
65 69
66 // WithProd installs the set of standard production AppEngine services: 70 // WithProd installs the set of standard production AppEngine services:
67 // * github.com/luci/luci-go/common/logging (set default level to debug). 71 // * github.com/luci/luci-go/common/logging (set default level to debug).
72 // * github.com/luci/luci-go/common/data/rand/mathrand.
68 // * github.com/luci/gae/impl/prod (production appengine services) 73 // * github.com/luci/gae/impl/prod (production appengine services)
69 // * github.com/luci/luci-go/appengine/gaeauth/client (appengine urlfetch tran sport) 74 // * github.com/luci/luci-go/appengine/gaeauth/client (appengine urlfetch tran sport)
70 // * github.com/luci/luci-go/server/proccache (in process memory cache) 75 // * github.com/luci/luci-go/server/proccache (in process memory cache)
71 // * github.com/luci/luci-go/server/settings (global app settings) 76 // * github.com/luci/luci-go/server/settings (global app settings)
72 // * github.com/luci/luci-go/appengine/gaesecrets (access to secret keys in da tastore) 77 // * github.com/luci/luci-go/appengine/gaesecrets (access to secret keys in da tastore)
73 // * github.com/luci/luci-go/appengine/gaeauth/server/gaesigner (RSA signer) 78 // * github.com/luci/luci-go/appengine/gaeauth/server/gaesigner (RSA signer)
74 // * github.com/luci/luci-go/appengine/gaeauth/server/auth (user groups databa se) 79 // * github.com/luci/luci-go/appengine/gaeauth/server/auth (user groups databa se)
75 func WithProd(c context.Context, req *http.Request) context.Context { 80 func WithProd(c context.Context, req *http.Request) context.Context {
76 // These are needed to use fetchCachedSettings. 81 // These are needed to use fetchCachedSettings.
77 c = logging.SetLevel(c, logging.Debug) 82 c = logging.SetLevel(c, logging.Debug)
83 c = mathrand.SetRand(c, globalMathRand)
78 c = prod.Use(c, req) 84 c = prod.Use(c, req)
79 c = settings.Use(c, globalSettings) 85 c = settings.Use(c, globalSettings)
80 86
81 // Fetch and apply configuration stored in the datastore. 87 // Fetch and apply configuration stored in the datastore.
82 cachedSettings := fetchCachedSettings(c) 88 cachedSettings := fetchCachedSettings(c)
83 c = logging.SetLevel(c, cachedSettings.LoggingLevel) 89 c = logging.SetLevel(c, cachedSettings.LoggingLevel)
84 if !cachedSettings.DisableDSCache { 90 if !cachedSettings.DisableDSCache {
85 c = dscache.AlwaysFilterRDS(c) 91 c = dscache.AlwaysFilterRDS(c)
86 } 92 }
87 93
(...skipping 29 matching lines...) Expand all
117 // BaseProd returns a list of middleware: WithProd middleware, a panic catcher i f this 123 // BaseProd returns a list of middleware: WithProd middleware, a panic catcher i f this
118 // is not a devserver, and the monitoring middleware. 124 // is not a devserver, and the monitoring middleware.
119 func BaseProd() router.MiddlewareChain { 125 func BaseProd() router.MiddlewareChain {
120 if appengine.IsDevAppServer() { 126 if appengine.IsDevAppServer() {
121 return router.NewMiddlewareChain(ProdServices, globalTsMonState. Middleware) 127 return router.NewMiddlewareChain(ProdServices, globalTsMonState. Middleware)
122 } 128 }
123 return router.NewMiddlewareChain( 129 return router.NewMiddlewareChain(
124 ProdServices, middleware.WithPanicCatcher, globalTsMonState.Midd leware, 130 ProdServices, middleware.WithPanicCatcher, globalTsMonState.Midd leware,
125 ) 131 )
126 } 132 }
OLDNEW
« 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