##// END OF EJS Templates
small fixes for test crawler
marcink -
r1341:1881b808 beta
parent child Browse files
Show More
@@ -1,139 +1,146 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """
2 """
3 rhodecode.tests.test_crawer
3 rhodecode.tests.test_crawer
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
5
6 Test for crawling a project for memory usage
6 Test for crawling a project for memory usage
7
7
8 watch -n1 ./rhodecode/tests/mem_watch
8 watch -n1 ./rhodecode/tests/mem_watch
9
9
10 :created_on: Apr 21, 2010
10 :created_on: Apr 21, 2010
11 :author: marcink
11 :author: marcink
12 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
12 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
13 :license: GPLv3, see COPYING for more details.
13 :license: GPLv3, see COPYING for more details.
14 """
14 """
15 # This program is free software: you can redistribute it and/or modify
15 # This program is free software: you can redistribute it and/or modify
16 # it under the terms of the GNU General Public License as published by
16 # it under the terms of the GNU General Public License as published by
17 # the Free Software Foundation, either version 3 of the License, or
17 # the Free Software Foundation, either version 3 of the License, or
18 # (at your option) any later version.
18 # (at your option) any later version.
19 #
19 #
20 # This program is distributed in the hope that it will be useful,
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
23 # GNU General Public License for more details.
24 #
24 #
25 # You should have received a copy of the GNU General Public License
25 # You should have received a copy of the GNU General Public License
26 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26 # along with this program. If not, see <http://www.gnu.org/licenses/>.
27
27
28
28
29 import cookielib
29 import cookielib
30 import urllib
30 import urllib
31 import urllib2
31 import urllib2
32 import vcs
32 import vcs
33 import time
33 import time
34
34
35 from os.path import join as jn
35 from os.path import join as jn
36
36
37
37
38 BASE_URI = 'http://127.0.0.1:5000/%s'
38 BASE_URI = 'http://127.0.0.1:5000/%s'
39 PROJECT = 'CPython'
39 PROJECT = 'CPython'
40 PROJECT_PATH = jn('/', 'home', 'marcink', 'hg_repos')
40 PROJECT_PATH = jn('/', 'home', 'marcink', 'hg_repos')
41
41
42
42
43 cj = cookielib.FileCookieJar('/tmp/rc_test_cookie.txt')
43 cj = cookielib.FileCookieJar('/tmp/rc_test_cookie.txt')
44 o = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
44 o = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
45 o.addheaders = [
45 o.addheaders = [
46 ('User-agent', 'rhodecode-crawler'),
46 ('User-agent', 'rhodecode-crawler'),
47 ('Accept-Language', 'en - us, en;q = 0.5')
47 ('Accept-Language', 'en - us, en;q = 0.5')
48 ]
48 ]
49
49
50 urllib2.install_opener(o)
50 urllib2.install_opener(o)
51
51
52
52
53
53
54 def test_changelog_walk(pages=100):
54 def test_changelog_walk(pages=100):
55 total_time = 0
55 total_time = 0
56 for i in range(1, pages):
56 for i in range(1, pages):
57
57
58 page = '/'.join((PROJECT, 'changelog',))
58 page = '/'.join((PROJECT, 'changelog',))
59
59
60 full_uri = (BASE_URI % page) + '?' + urllib.urlencode({'page':i})
60 full_uri = (BASE_URI % page) + '?' + urllib.urlencode({'page':i})
61 s = time.time()
61 s = time.time()
62 f = o.open(full_uri)
62 f = o.open(full_uri)
63 size = len(f.read())
63 size = len(f.read())
64 e = time.time() - s
64 e = time.time() - s
65 total_time += e
65 total_time += e
66 print 'visited %s size:%s req:%s ms' % (full_uri, size, e)
66 print 'visited %s size:%s req:%s ms' % (full_uri, size, e)
67
67
68
68
69 print 'total_time', total_time
69 print 'total_time', total_time
70 print 'average on req', total_time / float(pages)
70 print 'average on req', total_time / float(pages)
71
71
72
72
73 def test_changeset_walk(limit=None):
73 def test_changeset_walk(limit=None):
74 print 'processing', jn(PROJECT_PATH, PROJECT)
74 print 'processing', jn(PROJECT_PATH, PROJECT)
75 total_time = 0
75 total_time = 0
76
76
77 repo = vcs.get_repo(jn(PROJECT_PATH, PROJECT))
77 repo = vcs.get_repo(jn(PROJECT_PATH, PROJECT))
78 cnt = 0
78 cnt = 0
79 for i in repo:
79 for i in repo:
80 cnt += 1
80 cnt += 1
81 raw_cs = '/'.join((PROJECT, 'changeset', i.raw_id))
81 raw_cs = '/'.join((PROJECT, 'changeset', i.raw_id))
82 if limit and limit == cnt:
82 if limit and limit == cnt:
83 break
83 break
84
84
85 full_uri = (BASE_URI % raw_cs)
85 full_uri = (BASE_URI % raw_cs)
86 s = time.time()
86 s = time.time()
87 f = o.open(full_uri)
87 f = o.open(full_uri)
88 size = len(f.read())
88 size = len(f.read())
89 e = time.time() - s
89 e = time.time() - s
90 total_time += e
90 total_time += e
91 print 'visited %s\%s size:%s req:%s ms' % (full_uri, i, size, e)
91 print '%s visited %s\%s size:%s req:%s ms' % (cnt, full_uri, i, size, e)
92
92
93 print 'total_time', total_time
93 print 'total_time', total_time
94 print 'average on req', total_time / float(cnt)
94 print 'average on req', total_time / float(cnt)
95
95
96
96
97 def test_files_walk():
97 def test_files_walk(limit=100):
98 print 'processing', jn(PROJECT_PATH, PROJECT)
98 print 'processing', jn(PROJECT_PATH, PROJECT)
99 total_time = 0
99 total_time = 0
100
100
101 repo = vcs.get_repo(jn(PROJECT_PATH, PROJECT))
101 repo = vcs.get_repo(jn(PROJECT_PATH, PROJECT))
102
102
103 from rhodecode.lib.oset import OrderedSet
103 from rhodecode.lib.oset import OrderedSet
104
104
105 paths_ = OrderedSet([''])
105 paths_ = OrderedSet([''])
106 try:
106 try:
107 tip = repo.get_changeset('tip')
107 tip = repo.get_changeset('tip')
108 for topnode, dirs, files in tip.walk('/'):
108 for topnode, dirs, files in tip.walk('/'):
109
109
110 for dir in dirs:
110 for dir in dirs:
111 paths_.add(dir.path)
111 paths_.add(dir.path)
112 for f in dir:
112 for f in dir:
113 paths_.add(f.path)
113 paths_.add(f.path)
114
114
115 for f in files:
115 for f in files:
116 paths_.add(f.path)
116 paths_.add(f.path)
117
117
118 except vcs.exception.RepositoryError, e:
118 except vcs.exception.RepositoryError, e:
119 pass
119 pass
120
120
121 cnt = 0
121 for f in paths_:
122 for f in paths_:
123 cnt += 1
124 if limit and limit == cnt:
125 break
126
122 file_path = '/'.join((PROJECT, 'files', 'tip', f))
127 file_path = '/'.join((PROJECT, 'files', 'tip', f))
123
128
124 full_uri = (BASE_URI % file_path)
129 full_uri = (BASE_URI % file_path)
125 s = time.time()
130 s = time.time()
126 f = o.open(full_uri)
131 f = o.open(full_uri)
127 size = len(f.read())
132 size = len(f.read())
128 e = time.time() - s
133 e = time.time() - s
129 total_time += e
134 total_time += e
130 print 'visited %s size:%s req:%s ms' % (full_uri, size, e)
135 print '%s visited %s size:%s req:%s ms' % (cnt, full_uri, size, e)
131
136
132 print 'total_time', total_time
137 print 'total_time', total_time
133 print 'average on req', total_time / float(len(repo))
138 print 'average on req', total_time / float(cnt)
139
134
140
135
141
136 test_files_walk()
137 test_changelog_walk(40)
142 test_changelog_walk(40)
143 time.sleep(2)
138 test_changeset_walk(limit=100)
144 test_changeset_walk(limit=100)
139
145 time.sleep(2)
146 test_files_walk(100)
General Comments 0
You need to be logged in to leave comments. Login now