Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
8caeb7f4
Commit
8caeb7f4
authored
Aug 01, 2010
by
Hanno Schlichting
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Encapsulate priority map
parent
fdb6a1a7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
23 deletions
+22
-23
src/Products/ZCatalog/plan.py
src/Products/ZCatalog/plan.py
+22
-23
No files found.
src/Products/ZCatalog/plan.py
View file @
8caeb7f4
...
...
@@ -25,8 +25,22 @@ REFRESH_RATE = 100
REPORTS_LOCK
=
allocate_lock
()
REPORTS
=
{}
PRIORITYMAP_LOCK
=
allocate_lock
()
PRIORITYMAP
=
{}
class
ThreadDict
(
object
):
@
classmethod
def
get_entry
(
cls
,
key
):
return
cls
.
value
.
get
(
key
,
None
)
@
classmethod
def
set_entry
(
cls
,
key
,
value
):
with
cls
.
lock
:
cls
.
value
[
key
]
=
value
class
PriorityMap
(
ThreadDict
):
lock
=
allocate_lock
()
value
=
{}
class
ValueIndexes
(
object
):
...
...
@@ -128,6 +142,7 @@ class CatalogPlan(object):
self
.
catalog
=
catalog
self
.
query
=
query
self
.
key
=
make_key
(
catalog
,
query
)
self
.
benchmark
=
{}
self
.
threshold
=
threshold
self
.
cid
=
self
.
get_id
()
self
.
init_timer
()
...
...
@@ -148,16 +163,8 @@ class CatalogPlan(object):
self
.
stop_time
=
None
self
.
duration
=
None
def
benchmark
(
self
):
# holds the benchmark of each index
bm
=
PRIORITYMAP
.
get
(
self
.
key
,
None
)
if
bm
is
None
:
with
PRIORITYMAP_LOCK
:
PRIORITYMAP
[
self
.
key
]
=
{}
return
bm
def
plan
(
self
):
benchmark
=
self
.
benchmark
(
)
benchmark
=
PriorityMap
.
get_entry
(
self
.
key
)
if
not
benchmark
:
return
None
...
...
@@ -187,10 +194,9 @@ class CatalogPlan(object):
name
=
name
,
duration
=
current
-
start_time
,
num
=
length
))
# remember index's hits, search time and calls
benchmark
=
self
.
benchmark
()
benchmark
=
self
.
benchmark
if
name
not
in
benchmark
:
with
PRIORITYMAP_LOCK
:
benchmark
[
name
]
=
Benchmark
(
num
=
length
,
duration
=
dt
,
hits
=
1
)
benchmark
[
name
]
=
Benchmark
(
num
=
length
,
duration
=
dt
,
hits
=
1
)
else
:
num
,
duration
,
hits
=
benchmark
[
name
]
num
=
int
(((
num
*
hits
)
+
length
)
/
float
(
hits
+
1
))
...
...
@@ -199,19 +205,12 @@ class CatalogPlan(object):
if
hits
%
REFRESH_RATE
==
0
:
hits
=
0
hits
+=
1
with
PRIORITYMAP_LOCK
:
benchmark
[
name
]
=
Benchmark
(
num
,
duration
,
hits
)
benchmark
[
name
]
=
Benchmark
(
num
,
duration
,
hits
)
def
stop
(
self
):
self
.
end_time
=
time
.
time
()
self
.
duration
=
self
.
end_time
-
self
.
start_time
key
=
self
.
key
benchmark
=
self
.
benchmark
()
with
PRIORITYMAP_LOCK
:
PRIORITYMAP
[
key
]
=
benchmark
PriorityMap
.
set_entry
(
self
.
key
,
self
.
benchmark
)
self
.
log
()
def
log
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment