##// END OF EJS Templates
request-wrapper: don't collect at app level, we can do this at gunicorn level with better results.
marcink -
r760:015ed74d default
parent child Browse files
Show More
@@ -1,70 +1,64 b''
1 1 # RhodeCode VCSServer provides access to different vcs backends via network.
2 2 # Copyright (C) 2014-2019 RhodeCode GmbH
3 3 #
4 4 # This program is free software; you can redistribute it and/or modify
5 5 # it under the terms of the GNU General Public License as published by
6 6 # the Free Software Foundation; either version 3 of the License, or
7 7 # (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software Foundation,
16 16 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 17
18 18 import gc
19 19 import time
20 20 import logging
21 21
22 22
23 23 from vcsserver.utils import safe_str
24 24
25 25
26 26 log = logging.getLogger(__name__)
27 27
28 28
29 29 def get_access_path(request):
30 30 environ = request.environ
31 31 return environ.get('PATH_INFO')
32 32
33 33
34 34 def get_user_agent(environ):
35 35 return environ.get('HTTP_USER_AGENT')
36 36
37 37
38 38 class RequestWrapperTween(object):
39 39 def __init__(self, handler, registry):
40 40 self.handler = handler
41 41 self.registry = registry
42 self.gc_max_requests = 25
43 42
44 43 # one-time configuration code goes here
45 44
46 45 def __call__(self, request):
47 46 start = time.time()
48 47 try:
49 48 response = self.handler(request)
50 49 finally:
51 50 end = time.time()
52 51 total = end - start
53 52 count = request.request_count()
54 53 log.info(
55 54 'Req[%4s] IP: %s %s Request to %s time: %.4fs [%s]',
56 55 count, '127.0.0.1', request.environ.get('REQUEST_METHOD'),
57 56 safe_str(get_access_path(request)), total, get_user_agent(request.environ))
58 57
59 if self.gc_max_requests and count % self.gc_max_requests == 0:
60 log.debug('Performing gc.collect now')
61 gc_count = gc.collect()
62 log.debug('gc collection freed %s objects', gc_count)
63
64 58 return response
65 59
66 60
67 61 def includeme(config):
68 62 config.add_tween(
69 63 'vcsserver.tweens.request_wrapper.RequestWrapperTween',
70 64 )
General Comments 0
You need to be logged in to leave comments. Login now