Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly batch Client.delete_many() calls #184

Merged
merged 2 commits into from
Sep 5, 2018

Conversation

shargan
Copy link
Contributor

@shargan shargan commented Aug 31, 2018

Essentially the same change as #182 but for delete_many() and its underlying _misc_cmd() method. This includes benchmarks for the delete methods.

Benchmarks for the current codebase with irrelevant lines trimmed:

# python2.7
$ pytest --verbose --capture=no --no-cov -m benchmark pymemcache/test --keys 100 --count 10000
================================================ test session starts =================================================
platform darwin -- Python 2.7.15, pytest-3.7.4, py-1.6.0, pluggy-0.7.1 -- /Users/shargan/repos/pymemcache/.venv/bin/python

pymemcache/test/test_benchmark.py::test_bench_delete[pymemcache] 0.296519994736
pymemcache/test/test_benchmark.py::test_bench_delete_multi[pymemcache] 27.9956350327


# python3.6
$ pytest --verbose --capture=no --no-cov -m benchmark pymemcache/test --keys 100 --count 10000
================================================= test session starts =================================================
platform darwin -- Python 3.6.6, pytest-3.7.4, py-1.6.0, pluggy-0.7.1 -- /Users/shargan/repos/pymemcache/.venv36/bin/python3.6

pymemcache/test/test_benchmark.py::test_bench_delete[pymemcache] 0.2534470558166504
pymemcache/test/test_benchmark.py::test_bench_delete_multi[pymemcache] 25.861117839813232

With this diff applied, delete_multi() is significantly improved:

# python2.7
$ pytest --verbose --capture=no --no-cov -m benchmark pymemcache/test --keys 100 --count 10000
================================================ test session starts =================================================
platform darwin -- Python 2.7.15, pytest-3.7.4, py-1.6.0, pluggy-0.7.1 -- /Users/shargan/repos/pymemcache/.venv/bin/python

pymemcache/test/test_benchmark.py::test_bench_delete[pymemcache] 0.310829877853
pymemcache/test/test_benchmark.py::test_bench_delete_multi[pymemcache] 5.40752792358


# python3.6
$ pytest --verbose --capture=no --no-cov -m benchmark pymemcache/test --keys 100 --count 10000
================================================= test session starts =================================================
platform darwin -- Python 3.6.6, pytest-3.7.4, py-1.6.0, pluggy-0.7.1 -- /Users/shargan/repos/pymemcache/.venv36/bin/python3.6

pymemcache/test/test_benchmark.py::test_bench_delete[pymemcache] 0.30205321311950684
pymemcache/test/test_benchmark.py::test_bench_delete_multi[pymemcache] 6.920046091079712

@jparise jparise requested a review from cgordon August 31, 2018 14:34
@cgordon
Copy link
Collaborator

cgordon commented Aug 31, 2018

This one is going to require more time to review than I have this morning, so I'll try to take a closer look this weekend.

@shargan
Copy link
Contributor Author

shargan commented Aug 31, 2018

No rush. Thanks for being willing to consider it.

@jparise jparise mentioned this pull request Sep 4, 2018
@nichochar
Copy link
Collaborator

I looked at this and it looks OK, but I'll let @cgordon take a look and validate. Once he's happy with it, we can merge and cut a release.

Thanks for the change

if not self.sock:
self._connect()

try:
self.sock.sendall(cmd)
self.sock.sendall(b''.join(cmds))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I have a slight preference for joining here with the \r\n instead of adding it to each cmd, but it's not a huge deal.

@@ -648,13 +650,13 @@ def version(self):
A string of the memcached version.
"""
cmd = b"version\r\n"
result = self._misc_cmd(cmd, b'version', False)
results = self._misc_cmd([cmd], b'version', False)
before, _, after = results[0].partition(b' ')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for the improved readability!

@cgordon cgordon merged commit b80eb74 into pinterest:master Sep 5, 2018
@cgordon
Copy link
Collaborator

cgordon commented Sep 5, 2018

Looks great, apologies for the delay, and thank you!

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.

3 participants