Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
zodb
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Joshua
zodb
Commits
78ee0abe
Commit
78ee0abe
authored
Dec 04, 2008
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Repaired connectionDebugInfo.
use "import time" so we can mess with time.time in tests.
parent
15548c4a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
14 deletions
+58
-14
src/ZODB/DB.py
src/ZODB/DB.py
+16
-14
src/ZODB/tests/testDB.py
src/ZODB/tests/testDB.py
+42
-0
No files found.
src/ZODB/DB.py
View file @
78ee0abe
...
@@ -17,12 +17,14 @@ $Id$"""
...
@@ -17,12 +17,14 @@ $Id$"""
import
warnings
import
warnings
import
cPickle
,
cStringIO
,
sys
import
cPickle
import
cStringIO
import
sys
import
threading
import
threading
from
time
import
time
,
ctime
import
logging
import
logging
import
datetime
import
datetime
import
calendar
import
calendar
import
time
from
ZODB.broken
import
find_global
from
ZODB.broken
import
find_global
from
ZODB.utils
import
z64
from
ZODB.utils
import
z64
...
@@ -109,7 +111,8 @@ class AbstractConnectionPool(object):
...
@@ -109,7 +111,8 @@ class AbstractConnectionPool(object):
class
ConnectionPool
(
AbstractConnectionPool
):
class
ConnectionPool
(
AbstractConnectionPool
):
def
__init__
(
self
,
size
,
timeout
=
time
()):
# XXX WTF, passing time.time() as a default?
def
__init__
(
self
,
size
,
timeout
=
time
.
time
()):
super
(
ConnectionPool
,
self
).
__init__
(
size
,
timeout
)
super
(
ConnectionPool
,
self
).
__init__
(
size
,
timeout
)
# A stack of connections available to hand out. This is a subset
# A stack of connections available to hand out. This is a subset
...
@@ -129,7 +132,7 @@ class ConnectionPool(AbstractConnectionPool):
...
@@ -129,7 +132,7 @@ class ConnectionPool(AbstractConnectionPool):
assert
c
not
in
self
.
available
assert
c
not
in
self
.
available
self
.
_reduce_size
(
strictly_less
=
True
)
self
.
_reduce_size
(
strictly_less
=
True
)
self
.
all
.
add
(
c
)
self
.
all
.
add
(
c
)
self
.
available
.
append
((
time
(),
c
))
self
.
available
.
append
((
time
.
time
(),
c
))
n
=
len
(
self
.
all
)
n
=
len
(
self
.
all
)
limit
=
self
.
size
limit
=
self
.
size
if
n
>
limit
:
if
n
>
limit
:
...
@@ -148,14 +151,14 @@ class ConnectionPool(AbstractConnectionPool):
...
@@ -148,14 +151,14 @@ class ConnectionPool(AbstractConnectionPool):
assert
c
in
self
.
all
assert
c
in
self
.
all
assert
c
not
in
self
.
available
assert
c
not
in
self
.
available
self
.
_reduce_size
(
strictly_less
=
True
)
self
.
_reduce_size
(
strictly_less
=
True
)
self
.
available
.
append
((
time
(),
c
))
self
.
available
.
append
((
time
.
time
(),
c
))
def
_reduce_size
(
self
,
strictly_less
=
False
):
def
_reduce_size
(
self
,
strictly_less
=
False
):
"""Throw away the oldest available connections until we're under our
"""Throw away the oldest available connections until we're under our
target size (strictly_less=False, the default) or no more than that
target size (strictly_less=False, the default) or no more than that
(strictly_less=True).
(strictly_less=True).
"""
"""
threshhold
=
time
()
-
self
.
timeout
threshhold
=
time
.
time
()
-
self
.
timeout
target
=
self
.
size
target
=
self
.
size
if
strictly_less
:
if
strictly_less
:
target
-=
1
target
-=
1
...
@@ -210,7 +213,7 @@ class ConnectionPool(AbstractConnectionPool):
...
@@ -210,7 +213,7 @@ class ConnectionPool(AbstractConnectionPool):
If a connection is no longer viable because it has timed out, it is
If a connection is no longer viable because it has timed out, it is
garbage collected."""
garbage collected."""
threshhold
=
time
()
-
self
.
timeout
threshhold
=
time
.
time
()
-
self
.
timeout
for
t
,
c
in
list
(
self
.
available
):
for
t
,
c
in
list
(
self
.
available
):
if
t
<
threshhold
:
if
t
<
threshhold
:
del
self
.
available
[
t
]
del
self
.
available
[
t
]
...
@@ -227,7 +230,7 @@ class KeyedConnectionPool(AbstractConnectionPool):
...
@@ -227,7 +230,7 @@ class KeyedConnectionPool(AbstractConnectionPool):
# see the comments in ConnectionPool for method descriptions.
# see the comments in ConnectionPool for method descriptions.
def
__init__
(
self
,
size
,
timeout
=
time
()):
def
__init__
(
self
,
size
,
timeout
=
time
.
time
()):
super
(
KeyedConnectionPool
,
self
).
__init__
(
size
,
timeout
)
super
(
KeyedConnectionPool
,
self
).
__init__
(
size
,
timeout
)
self
.
pools
=
{}
self
.
pools
=
{}
...
@@ -741,7 +744,7 @@ class DB(object):
...
@@ -741,7 +744,7 @@ class DB(object):
def
connectionDebugInfo
(
self
):
def
connectionDebugInfo
(
self
):
result
=
[]
result
=
[]
t
=
time
()
t
=
time
.
time
()
def
get_info
(
c
):
def
get_info
(
c
):
# `result`, `time` and `before` are lexically inherited.
# `result`, `time` and `before` are lexically inherited.
...
@@ -755,13 +758,12 @@ class DB(object):
...
@@ -755,13 +758,12 @@ class DB(object):
d
=
"%s (%s)"
%
(
d
,
len
(
c
.
_cache
))
d
=
"%s (%s)"
%
(
d
,
len
(
c
.
_cache
))
result
.
append
({
result
.
append
({
'opened'
:
o
and
(
"%s (%.2fs)"
%
(
ctime
(
o
),
t
-
o
)),
'opened'
:
o
and
(
"%s (%.2fs)"
%
(
time
.
ctime
(
o
),
t
-
o
)),
'info'
:
d
,
'info'
:
d
,
'before'
:
before
,
'before'
:
c
.
before
,
})
})
for
before
,
pool
in
self
.
_pools
.
items
():
self
.
_connectionMap
(
get_info
)
pool
.
map
(
get_info
)
return
result
return
result
def
getActivityMonitor
(
self
):
def
getActivityMonitor
(
self
):
...
@@ -783,7 +785,7 @@ class DB(object):
...
@@ -783,7 +785,7 @@ class DB(object):
time if t is not specified.
time if t is not specified.
"""
"""
if
t
is
None
:
if
t
is
None
:
t
=
time
()
t
=
time
.
time
()
t
-=
days
*
86400
t
-=
days
*
86400
try
:
try
:
self
.
storage
.
pack
(
t
,
self
.
references
)
self
.
storage
.
pack
(
t
,
self
.
references
)
...
...
src/ZODB/tests/testDB.py
View file @
78ee0abe
...
@@ -104,6 +104,48 @@ def test_invalidateCache():
...
@@ -104,6 +104,48 @@ def test_invalidateCache():
>>> db.close()
>>> db.close()
"""
"""
def
test_connectionDebugInfo
():
r"""DB.connectionDebugInfo provides information about connections.
>>> import time
>>> now = 1228423244.5
>>> def faux_time():
... global now
... now += .1
... return now
>>> real_time = time.time
>>> time.time = faux_time
>>> from ZODB.tests.util import DB
>>> import transaction
>>> db = DB()
>>> c1 = db.open()
>>> c1.setDebugInfo('test info')
>>> c1.root()['a'] = MinPO(1)
>>> transaction.commit()
>>> c2 = db.open()
>>> _ = c1.root()['a']
>>> c2.close()
>>> c3 = db.open(before=c1.root()._p_serial)
>>> info = db.connectionDebugInfo()
>>> import pprint
>>> pprint.pprint(info, width=1)
[{'before': None,
'info': ' (0)',
'opened': None},
{'before': None,
'info': 'test info (2)',
'opened': 'Thu Dec 4 15:40:44 2008 (1.40s)'},
{'before': '\x03zY\xd8\xc0m9\xdd',
'info': ' (0)',
'opened': 'Thu Dec 4 15:40:45 2008 (0.30s)'}]
>>> time.time = real_time
"""
def
test_suite
():
def
test_suite
():
s
=
unittest
.
makeSuite
(
DBTests
)
s
=
unittest
.
makeSuite
(
DBTests
)
...
...
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