Skip to content

Fixed over publishing, improved publication tests, and increased publication speed - #363

Merged
gerrod3 merged 3 commits into
pulp:masterfrom
gerrod3:publication_tests
Apr 29, 2021
Merged

Fixed over publishing, improved publication tests, and increased publication speed#363
gerrod3 merged 3 commits into
pulp:masterfrom
gerrod3:publication_tests

Conversation

@gerrod3

@gerrod3 gerrod3 commented Apr 23, 2021

Copy link
Copy Markdown
Contributor

fixes: #347
fixes: #362

@gerrod3 gerrod3 added this to the 3.3.0 milestone Apr 23, 2021
@gerrod3
gerrod3 force-pushed the publication_tests branch 4 times, most recently from 74218c8 to bd33d49 Compare April 23, 2021 20:21
Comment thread pulp_python/app/tasks/publish.py Outdated

@gerrod3 gerrod3 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This publication optimization is pretty much a full refactor and it's quick. I did a test with a repository with 2000 packages and 375,000 releases and it took 29 mins for the current way, and 70 secs for this new optimized way. With N as the number of packages and M as the number of releases, we currently do 1 + N + M database saves and 1 + N + 2M database queries (1 + N + M queries if sync is immediate) with all of the M queries just getting one element. With the new optimization we will do 2 + N database saves and 3 database queries (for both on_demand and immediate sync, can be dropped to 2, see comments below). The memory usage could possibly grow quite large, but that can be optimize if we break up the large database saves into smaller batches.

Comment thread pulp_python/app/tasks/publish.py Outdated
Comment on lines +111 to +113
release_content_artifacts = python_models.PythonPackageContent.objects.filter(pk__in=publication.repository_version.content).values_list("contentartifact", flat=True)
remote_artifacts = models.RemoteArtifact.objects.filter(content_artifact__in=release_content_artifacts).values_list("content_artifact", "sha256").iterator()
checksums = {ca: sha for ca, sha in remote_artifacts} # This can grow to 4 million elements if fully PyPI synced

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The remote_artifacts query can be removed (along with release_content_artifacts although that query shouldn't be evaluated) if we add sha256 to the PythonPackageContent model. We have to get the remote artifacts incase the sync is on_demand because the download links require the sha256 be present. While the query has been optimize to be quick and take up little memory the dictionary checksums that I create from it is really large and can grow to be up to 4 million elements (number of releases available on PyPI). I need to do more tests to check how bad the memory usuage is, but I have a feeling this optimization is needed to prevent going OOM.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potentially we should do that anyways if filename is not a workable (global) uniqueness constraint.

Comment thread pulp_python/app/tasks/publish.py Outdated
ind = 0
current_name = index_names[ind][0]
package_releases = []
published_artifacts = [] # This list can grow up to 4 million elements for full PyPI, can be cleared if we do multiple bulk_creates

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This list can also grow up to 4 million elements, but it can be cleared if I bulk_create after every N releases.

Comment thread pulp_python/app/tasks/publish.py Outdated
content_artifact_id=content_artifact
))
write_project_page() # Write the final project's page
models.PublishedArtifact.objects.bulk_create(published_artifacts) # maybe play around with batch size?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not so sure if this bulk_create will do well with a list of 4 million elements, but it worked fine for my test with 375,000. It's possible there is some hard-coded batch-size limit under the hood that will choose the best number for us, but I'm not sure.

@dralley dralley Apr 28, 2021

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Django does do internal batching and enforces a max batch size, but I would set one manually here. 2000 would be fine.

https://github.com/django/django/blob/main/django/db/models/query.py#L547-L548

Although - and I might be misunderstanding pass_through, I thought that the purpose was to avoid manually saving published artifacts?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is from before I was setting pass_through. I got rid of this and the extra published_artifacts as they are no longer needed.

@gerrod3 gerrod3 changed the title Fixed over publishing and improved publication tests Fixed over publishing, improved publication tests, and increased publication speed Apr 24, 2021
@gerrod3
gerrod3 force-pushed the publication_tests branch 3 times, most recently from 2135352 to 10548da Compare April 24, 2021 15:15
@gerrod3
gerrod3 force-pushed the publication_tests branch 4 times, most recently from 00b8dba to 44a3a1e Compare April 27, 2021 17:49
Comment thread pulp_python/app/tasks/publish.py Outdated
Comment thread pulp_python/app/tasks/publish.py
Comment thread pulp_python/app/tasks/publish.py
Comment thread pulp_python/app/tasks/publish.py Outdated
Comment thread pulp_python/tests/functional/api/test_crud_publications.py
@gerrod3
gerrod3 force-pushed the publication_tests branch from 44a3a1e to 56b0054 Compare April 28, 2021 18:52
@gerrod3
gerrod3 force-pushed the publication_tests branch from 56b0054 to 4cad081 Compare April 28, 2021 18:56
@gerrod3
gerrod3 merged commit b6dd8ca into pulp:master Apr 29, 2021
@gerrod3
gerrod3 deleted the publication_tests branch April 29, 2021 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Publications publish more content then is in the repository Improve Publications functional tests

2 participants