Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
snippets
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
Model registry
Operate
Environments
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
Platform
Development
snippets
Commits
449ec858
Verified
Commit
449ec858
authored
1 month ago
by
Antoine Lambert
Browse files
Options
Downloads
Patches
Plain Diff
Add Python script to compute SWH graph object size with GRPC API
parent
ae9cab80
No related branches found
Branches containing commit
Tags
swh-storage-replayer-20240213.1
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
anlambert/graph-object-size-grpc.py
+85
-0
85 additions, 0 deletions
anlambert/graph-object-size-grpc.py
anlambert/requirements.txt
+1
-0
1 addition, 0 deletions
anlambert/requirements.txt
with
86 additions
and
0 deletions
anlambert/graph-object-size-grpc.py
0 → 100755
+
85
−
0
View file @
449ec858
#!/usr/bin/env python3
# Copyright (C) 2025 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
import
time
import
click
import
grpc
import
humanize
import
swh.graph.grpc.swhgraph_pb2
as
swhgraph
import
swh.graph.grpc.swhgraph_pb2_grpc
as
swhgraph_grpc
GRAPH_GRPC_SERVER
=
"
maxxi.internal.softwareheritage.org:50091
"
@click.command
()
@click.option
(
"
--swh-graph-grpc-server
"
,
"
-g
"
,
default
=
GRAPH_GRPC_SERVER
,
show_default
=
True
,
help
=
"
URL of swh-graph GRPC server
"
,
required
=
True
,
)
@click.option
(
"
--max-message-length
"
,
"
-l
"
,
default
=
1024
*
1024
*
1024
,
show_default
=
True
,
help
=
"
Maximum length of GRPC messages
"
,
required
=
True
,
)
@click.argument
(
"
swhid
"
,
nargs
=
1
,
required
=
True
)
def
run
(
swh_graph_grpc_server
,
max_message_length
,
swhid
):
"""
Compute a set of metrics for the SWHID passed as parameter by
performing a BFS from the associated node in the SWH graph using the GRPC API:
- number of induced subgraph nodes
- total number of content objects
- total number of skipped contents
- total content objects size in bytes
"""
nb_subgraph_nodes
=
0
nb_contents
=
0
nb_skipped_contents
=
0
total_contents_size
=
0
with
grpc
.
insecure_channel
(
swh_graph_grpc_server
,
options
=
[
(
"
grpc.max_message_length
"
,
max_message_length
),
(
"
grpc.max_send_message_length
"
,
max_message_length
),
(
"
grpc.max_receive_message_length
"
,
max_message_length
),
],
)
as
channel
:
start
=
time
.
perf_counter
()
stub
=
swhgraph_grpc
.
TraversalServiceStub
(
channel
)
response
=
stub
.
Traverse
(
swhgraph
.
TraversalRequest
(
src
=
[
swhid
]))
for
item
in
response
:
nb_subgraph_nodes
+=
1
if
item
.
swhid
.
startswith
(
"
swh:1:cnt:
"
):
if
not
item
.
cnt
.
is_skipped
:
nb_contents
+=
1
total_contents_size
+=
item
.
cnt
.
length
else
:
nb_skipped_contents
+=
1
end
=
time
.
perf_counter
()
elapsed_time
=
humanize
.
naturaldelta
(
end
-
start
,
minimum_unit
=
"
microseconds
"
)
print
(
f
"
BFS execution time =
{
elapsed_time
}
"
)
print
(
f
"
number of subgraph nodes:
{
nb_subgraph_nodes
}
"
)
print
(
f
"
number of contents:
{
nb_contents
}
"
)
print
(
f
"
number of skipped contents:
{
nb_skipped_contents
}
"
)
total_size
=
humanize
.
naturalsize
(
total_contents_size
,
binary
=
True
)
print
(
f
"
total contents size in bytes:
{
total_size
}
"
)
if
__name__
==
"
__main__
"
:
run
()
This diff is collapsed.
Click to expand it.
anlambert/requirements.txt
+
1
−
0
View file @
449ec858
boto3
chardet
click
humanize
ndjson
pyspark
python-keycloak
...
...
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