Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inventory-provider
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
geant-swd
dashboardv3
inventory-provider
Commits
1aa3e9ee
Commit
1aa3e9ee
authored
4 years ago
by
Robert Latta
Browse files
Options
Downloads
Patches
Plain Diff
_load_redis_docs can now take an itterable
parent
4f50234c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
inventory_provider/routes/common.py
+19
-9
19 additions, 9 deletions
inventory_provider/routes/common.py
with
19 additions
and
9 deletions
inventory_provider/routes/common.py
+
19
−
9
View file @
1aa3e9ee
...
@@ -131,6 +131,8 @@ def _redis_client_proc(key_queue, value_queue, config_params, doc_type):
...
@@ -131,6 +131,8 @@ def _redis_client_proc(key_queue, value_queue, config_params, doc_type):
assert
doc_type
in
(
_DECODE_TYPE_JSON
,
_DECODE_TYPE_XML
)
assert
doc_type
in
(
_DECODE_TYPE_JSON
,
_DECODE_TYPE_XML
)
def
_decode
(
bv
):
def
_decode
(
bv
):
if
not
bv
:
return
value
=
bv
.
decode
(
'
utf-8
'
)
value
=
bv
.
decode
(
'
utf-8
'
)
if
doc_type
==
_DECODE_TYPE_JSON
:
if
doc_type
==
_DECODE_TYPE_JSON
:
return
json
.
loads
(
value
)
return
json
.
loads
(
value
)
...
@@ -146,10 +148,12 @@ def _redis_client_proc(key_queue, value_queue, config_params, doc_type):
...
@@ -146,10 +148,12 @@ def _redis_client_proc(key_queue, value_queue, config_params, doc_type):
if
not
key
:
if
not
key
:
break
break
value_queue
.
put
({
v
=
_decode
(
r
.
get
(
key
))
'
key
'
:
key
,
if
v
is
not
None
:
'
value
'
:
_decode
(
r
.
get
(
key
))
value_queue
.
put
({
})
'
key
'
:
key
,
'
value
'
:
v
})
except
json
.
JSONDecodeError
:
except
json
.
JSONDecodeError
:
logger
.
exception
(
f
'
error decoding entry for
{
key
}
'
)
logger
.
exception
(
f
'
error decoding entry for
{
key
}
'
)
...
@@ -172,7 +176,7 @@ def _load_redis_docs(
...
@@ -172,7 +176,7 @@ def _load_redis_docs(
the redis master the cumulative latency causes nginx/gunicorn timeouts
the redis master the cumulative latency causes nginx/gunicorn timeouts
:param config_params: app config
:param config_params: app config
:param pattern: key pattern to load
:param
key_
pattern: key pattern
or iterable of keys
to load
:param num_threads: number of client threads to create
:param num_threads: number of client threads to create
:param doc_type: decoding type to do (xml or json)
:param doc_type: decoding type to do (xml or json)
:return: yields dicts like {
'
key
'
: str,
'
value
'
: dict or xml doc}
:return: yields dicts like {
'
key
'
: str,
'
value
'
: dict or xml doc}
...
@@ -190,10 +194,16 @@ def _load_redis_docs(
...
@@ -190,10 +194,16 @@ def _load_redis_docs(
threads
.
append
({
'
thread
'
:
t
,
'
queue
'
:
q
})
threads
.
append
({
'
thread
'
:
t
,
'
queue
'
:
q
})
r
=
tasks_common
.
get_current_redis
(
config_params
)
r
=
tasks_common
.
get_current_redis
(
config_params
)
# scan with bigger batches, to mitigate network latency effects
for
k
in
r
.
scan_iter
(
key_pattern
,
count
=
1000
):
if
isinstance
(
key_pattern
,
str
):
t
=
random
.
choice
(
threads
)
# scan with bigger batches, to mitigate network latency effects
t
[
'
queue
'
].
put
(
k
.
decode
(
'
utf-8
'
))
for
k
in
r
.
scan_iter
(
key_pattern
,
count
=
1000
):
t
=
random
.
choice
(
threads
)
t
[
'
queue
'
].
put
(
k
.
decode
(
'
utf-8
'
))
else
:
for
k
in
key_pattern
:
t
=
random
.
choice
(
threads
)
t
[
'
queue
'
].
put
(
k
)
# tell all threads there are no more keys coming
# tell all threads there are no more keys coming
for
t
in
threads
:
for
t
in
threads
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment