Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE3
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
5
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
148a0972
authored
Jan 10, 2022
by
Szeberényi Imre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chache log & vnc log fix
parent
215075e2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
23 deletions
+32
-23
circle/circle/settings/local.py
+9
-2
circle/common/models.py
+21
-20
circle/dashboard/views/vm.py
+1
-0
circle/vm/models/node.py
+1
-1
No files found.
circle/circle/settings/local.py
View file @
148a0972
...
@@ -53,13 +53,20 @@ EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
...
@@ -53,13 +53,20 @@ EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
########## CACHE CONFIGURATION
########## CACHE CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#caches
CACHES
=
{
CACHES
=
{
'default'
:
{
'default'
:
{
'BACKEND'
:
'django.core.cache.backends.
dummy.Dummy
Cache'
,
'BACKEND'
:
'django.core.cache.backends.
memcached.PyLibMC
Cache'
,
'LOCATION'
:
'127.0.0.1:11211'
,
'LOCATION'
:
'127.0.0.1:11211'
,
}
}
}
}
# See: https://docs.djangoproject.com/en/dev/ref/settings/#caches
#CACHES = {
# 'default': {
# 'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
# 'LOCATION': '127.0.0.1:11211',
# }
#}
########## END CACHE CONFIGURATION
########## END CACHE CONFIGURATION
...
...
circle/common/models.py
View file @
148a0972
...
@@ -82,10 +82,9 @@ def activitycontextimpl(act, on_abort=None, on_commit=None):
...
@@ -82,10 +82,9 @@ def activitycontextimpl(act, on_abort=None, on_commit=None):
e
=
str
(
e
.
__class__
.
__name__
),
e
=
str
(
e
.
__class__
.
__name__
),
error
=
get_error_msg
(
e
))
error
=
get_error_msg
(
e
))
raise
raise
except
:
except
BaseException
as
e
:
logger
.
exception
(
"Failed activity
%
s"
%
str
(
act
))
logger
.
exception
(
"Failed activity
%
s"
%
str
(
act
))
handler
=
None
handler
=
None
if
on_abort
is
None
else
lambda
a
:
on_abort
(
a
,
e
)
# handler = None if on_abort is None else lambda a: on_abort(a, e)
act
.
finish
(
succeeded
=
False
,
result
=
result
,
event_handler
=
handler
)
act
.
finish
(
succeeded
=
False
,
result
=
result
,
event_handler
=
handler
)
raise
raise
else
:
else
:
...
@@ -274,16 +273,18 @@ def compute_cached(method, instance, memcached_seconds,
...
@@ -274,16 +273,18 @@ def compute_cached(method, instance, memcached_seconds,
result
=
method
(
instance
,
*
args
,
**
kwargs
)
result
=
method
(
instance
,
*
args
,
**
kwargs
)
# save to memcache
# save to memcache
cache
.
set
(
key
,
result
,
memcached_seconds
)
cache
.
set
(
key
,
result
,
memcached_seconds
)
elapsed
=
time
()
-
start
now
=
time
()
elapsed
=
now
-
start
cache
.
set
(
"
%
s.cached"
%
key
,
2
,
max
(
memcached_seconds
*
0.5
,
cache
.
set
(
"
%
s.cached"
%
key
,
2
,
max
(
memcached_seconds
*
0.5
,
memcached_seconds
*
0.75
-
elapsed
))
memcached_seconds
-
elapsed
))
logger
.
debug
(
'Value of <
%
s>.
%
s(
%
s)=<
%
s> saved to cache (
%
s elapsed).'
,
setattr
(
instance
,
key
,
{
'time'
:
start
,
'value'
:
result
})
str
(
instance
),
method
.
__name__
,
str
(
args
),
logger
.
debug
(
'Value of
%
s<
%
s>.
%
s(
%
s)=<
%
s> saved to cache (
%
s elapsed, key:
%
s).'
,
str
(
result
),
elapsed
)
str
(
method
.
__module__
),
str
(
instance
),
method
.
__name__
,
str
(
args
),
str
(
result
),
elapsed
,
key
)
return
result
return
result
def
method_cache
(
memcached_seconds
=
60
,
instance_seconds
=
5
):
# noqa
def
method_cache
(
memcached_seconds
=
60
,
instance_seconds
=
30
):
# noqa
"""Cache return value of decorated method to memcached and memory.
"""Cache return value of decorated method to memcached and memory.
:param memcached_seconds: Invalidate memcached results after this time.
:param memcached_seconds: Invalidate memcached results after this time.
...
@@ -307,12 +308,10 @@ def method_cache(memcached_seconds=60, instance_seconds=5): # noqa
...
@@ -307,12 +308,10 @@ def method_cache(memcached_seconds=60, instance_seconds=5): # noqa
method_name
=
method
.
__name__
method_name
=
method
.
__name__
def
get_key
(
instance
,
*
args
,
**
kwargs
):
def
get_key
(
instance
,
*
args
,
**
kwargs
):
print
(
str
(
method
.
__module__
)
+
method_name
+
concat_str
=
str
(
method
.
__module__
)
+
'<'
+
str
(
instance
)
+
'>'
+
'.'
+
method_name
+
str
(
args
)
+
str
(
kwargs
)
str
(
instance
.
id
)
+
key
=
sha224
(
concat_str
.
encode
(
'utf-8'
))
.
hexdigest
()
str
(
args
)
+
logger
.
debug
(
"concat_str:
%
s key:
%
s"
,
concat_str
,
key
)
str
(
kwargs
))
return
key
concat_str
=
str
(
method
.
__module__
)
+
method_name
+
str
(
instance
.
id
)
+
str
(
args
)
+
str
(
kwargs
)
return
sha224
(
concat_str
.
encode
(
'utf-8'
))
.
hexdigest
()
def
x
(
instance
,
*
args
,
**
kwargs
):
def
x
(
instance
,
*
args
,
**
kwargs
):
invalidate
=
kwargs
.
pop
(
'invalidate_cache'
,
False
)
invalidate
=
kwargs
.
pop
(
'invalidate_cache'
,
False
)
...
@@ -328,26 +327,28 @@ def method_cache(memcached_seconds=60, instance_seconds=5): # noqa
...
@@ -328,26 +327,28 @@ def method_cache(memcached_seconds=60, instance_seconds=5): # noqa
if
vals
[
'time'
]
+
instance_seconds
>
now
:
if
vals
[
'time'
]
+
instance_seconds
>
now
:
# has valid on class cache, return that
# has valid on class cache, return that
result
=
vals
[
'value'
]
result
=
vals
[
'value'
]
setattr
(
instance
,
key
,
{
'time'
:
now
,
'value'
:
result
})
#
setattr(instance, key, {'time': now, 'value': result})
if
result
is
None
:
if
result
is
None
:
result
=
cache
.
get
(
key
)
result
=
cache
.
get
(
key
)
if
invalidate
or
(
result
is
None
):
if
invalidate
or
(
result
is
None
):
logger
.
debug
(
"all caches failed, compute now
"
)
logger
.
debug
(
"all caches failed, compute now
(key,inv,res,sec:
%
s,
%
s,
%
s,
%
s)"
%
(
key
,
invalidate
,
result
,
memcached_seconds
)
)
result
=
compute_cached
(
method
,
instance
,
memcached_seconds
,
result
=
compute_cached
(
method
,
instance
,
memcached_seconds
,
key
,
time
(),
*
args
,
**
kwargs
)
key
,
time
(),
*
args
,
**
kwargs
)
setattr
(
instance
,
key
,
{
'time'
:
now
,
'value'
:
result
})
# setattr(instance, key, {'time': now, 'value': result})
logger
.
debug
(
"new key,result:
%
s,
%
s"
,
key
,
result
)
elif
not
cache
.
get
(
"
%
s.cached"
%
key
):
elif
not
cache
.
get
(
"
%
s.cached"
%
key
):
logger
.
debug
(
"
caches expiring, compute async"
)
logger
.
debug
(
"
%
s.caches expiring, compute async (
%
s sec)"
,
key
,
memcached_seconds
)
cache
.
set
(
"
%
s.cached"
%
key
,
1
,
memcached_seconds
*
0.5
)
cache
.
set
(
"
%
s.cached"
%
key
,
1
,
memcached_seconds
*
0.5
)
logger
.
debug
(
"
%
s.caches set
%
s"
,
key
,
cache
.
get
(
"
%
s.cached"
%
key
))
try
:
try
:
compute_cached
.
apply_async
(
compute_cached
.
apply_async
(
queue
=
'localhost.man'
,
kwargs
=
kwargs
,
args
=
[
queue
=
'localhost.man'
,
kwargs
=
kwargs
,
args
=
[
method_name
,
(
instance
.
__class__
,
instance
.
id
),
method_name
,
(
instance
.
__class__
,
instance
.
id
),
memcached_seconds
,
key
,
time
()]
+
list
(
args
))
memcached_seconds
,
key
,
time
()]
+
list
(
args
))
except
:
except
:
logger
.
exception
(
"Couldnt compute async
%
s
"
,
method_name
)
logger
.
exception
(
"Couldnt compute async
%
s
key
%
s"
,
method_name
,
key
)
return
result
return
result
...
...
circle/dashboard/views/vm.py
View file @
148a0972
...
@@ -104,6 +104,7 @@ class VmDetailVncTokenView(CheckedDetailView):
...
@@ -104,6 +104,7 @@ class VmDetailVncTokenView(CheckedDetailView):
host
=
str
(
self
.
object
.
node
.
host
.
ipv4
)
host
=
str
(
self
.
object
.
node
.
host
.
ipv4
)
value
=
signing
.
dumps
({
'host'
:
host
,
'port'
:
port
},
value
=
signing
.
dumps
({
'host'
:
host
,
'port'
:
port
},
key
=
getenv
(
"PROXY_SECRET"
,
'asdasd'
)),
key
=
getenv
(
"PROXY_SECRET"
,
'asdasd'
)),
logger
.
debug
(
'vnc host:
%
s vnc port:
%
s value:
%
s'
,
host
,
port
,
value
)
return
HttpResponse
(
'vnc/?d=
%
s'
%
value
)
return
HttpResponse
(
'vnc/?d=
%
s'
%
value
)
else
:
else
:
raise
Http404
()
raise
Http404
()
...
...
circle/vm/models/node.py
View file @
148a0972
...
@@ -259,7 +259,7 @@ class Node(OperatedMixin, TimeStampedModel):
...
@@ -259,7 +259,7 @@ class Node(OperatedMixin, TimeStampedModel):
"""
"""
return
self
.
ram_size
*
self
.
overcommit
return
self
.
ram_size
*
self
.
overcommit
@method_cache
(
30
)
@method_cache
(
30
0
)
def
get_remote_queue_name
(
self
,
queue_id
,
priority
=
None
):
def
get_remote_queue_name
(
self
,
queue_id
,
priority
=
None
):
"""Returns the name of the remote celery queue for this node.
"""Returns the name of the remote celery queue for this node.
...
...
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