##// END OF EJS Templates
scripts: added timeout flag to load script measuring url times
marcink -
r3858:1ae1aad2 default
parent child Browse files
Show More
@@ -1,73 +1,74 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2010-2019 RhodeCode GmbH
3 # Copyright (C) 2010-2019 RhodeCode GmbH
4 #
4 #
5 # This program is free software: you can redistribute it and/or modify
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License, version 3
6 # it under the terms of the GNU Affero General Public License, version 3
7 # (only), as published by the Free Software Foundation.
7 # (only), as published by the Free Software Foundation.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU Affero General Public License
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
16 #
17 # This program is dual-licensed. If you wish to learn more about the
17 # This program is dual-licensed. If you wish to learn more about the
18 # RhodeCode Enterprise Edition, including its added features, Support services,
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
20
21 import timeit
21 import timeit
22 import logging
22 import logging
23 import click
23 import click
24
24
25 log = logging.getLogger(__name__)
25 log = logging.getLogger(__name__)
26
26
27
27
28 @click.command()
28 @click.command()
29 @click.option('--server', help='Server url to connect to. e.g http://rc.local.com', required=True)
29 @click.option('--server', help='Server url to connect to. e.g http://rc.local.com', required=True)
30 @click.option('--pages', help='load pages to visit from a file', required=True, type=click.File())
30 @click.option('--pages', help='load pages to visit from a file', required=True, type=click.File())
31 @click.option('--repeat', help='number of times to repeat', default=10, type=int)
31 @click.option('--repeat', help='number of times to repeat', default=10, type=int)
32 def main(server, repeat, pages):
32 @click.option('--timeout', help='call timeout', default=60, type=int)
33 def main(server, repeat, pages, timeout):
33
34
34 print("Repeating each URL %d times\n" % repeat)
35 print("Repeating each URL %d times\n" % repeat)
35 pages = pages.readlines()
36 pages = pages.readlines()
36
37
37 for page_url in pages:
38 for page_url in pages:
38
39
39 url = "%s/%s" % (server, page_url.strip())
40 url = "%s/%s" % (server, page_url.strip())
40 print(url)
41 print(url)
41
42
42 stmt = "requests.get('%s', timeout=120)" % url
43 stmt = "requests.get('{}', timeout={})".format(url, timeout)
43 t = timeit.Timer(stmt=stmt, setup="import requests")
44 t = timeit.Timer(stmt=stmt, setup="import requests")
44
45
45 result = t.repeat(repeat=repeat, number=1)
46 result = t.repeat(repeat=repeat, number=1)
46 print(" %.4f (min) - %.4f (max) - %.4f (avg)\n" %
47 print(" %.4f (min) - %.4f (max) - %.4f (avg)\n" %
47 (min(result), max(result), sum(result) / len(result)))
48 (min(result), max(result), sum(result) / len(result)))
48
49
49
50
50 if __name__ == '__main__':
51 if __name__ == '__main__':
51 main()
52 main()
52
53
53
54
54
55
55
56
56
57
57
58
58
59
59
60
60
61
61
62
62
63
63
64
64
65
65
66
66
67
67
68
68
69
69
70
70
71
71
72
72
73
73
74
General Comments 0
You need to be logged in to leave comments. Login now