Opened 15 years ago

Closed 13 years ago

Last modified 12 years ago

#11675 closed (fixed)

Support new memcached wrapper pylibmc

Reported by: pippejp@… Owned by: otherjacob
Component: Core (Cache system) Version: dev
Severity: Keywords: cache pylibmc memcached.py
Cc: danger@…, tomasz.elendt@…, nikitka@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

pylibmc is a python wrapper around the libmemcache C library.

According to the site, it is faster than cmemcache.

The API is pretty much python-memcached, so I added the fallback: pylibmc -> cmemcache -> memcache.

The patch contains more about eternal caching.

This is my first patch. Thank you.

Attachments (2)

memcached.py.diff (2.2 KB ) - added by anonymous 15 years ago.
test.diff (1.4 KB ) - added by Jeff Ammons 14 years ago.
Test for our proposed fix

Download all attachments as: .zip

Change History (23)

by anonymous, 15 years ago

Attachment: memcached.py.diff added

comment:1 by pippejp@…, 15 years ago

Sorry, attachment is mine.

comment:2 by Alex Gaynor, 15 years ago

Triage Stage: UnreviewedAccepted

I'm marking this accepted, but I don't think implementing *another* fallback is the right way to go. I think the Memcached backend should just have a class "connection_class" attribute and then people can subclass the backend to add support for new memcached wrappers.

comment:3 by stefantalpalaru, 15 years ago

This is actually a wrapper around libmemcached: http://tangent.org/552/libmemcached.html
It exposes a lot more functionality than the other ones. Just to name a few: set_multi(), delete_multi(), flush_all(), prepend(), append().

comment:4 by otherjacob, 14 years ago

Has patch: unset
Owner: changed from nobody to otherjacob
Status: newassigned

I'm going to go ahead and adopt Alex's suggestion for future library support.

comment:5 by Jeff Ammons, 14 years ago

So rather than add other fallback we were thinking that one could specify the preferred memcached backend as follows:
CACHE_BACKEND = memcached://server:port?lib=memcache

Where memcache could be cmemcache, memcache, or some other python module. If an engine is not specified, it will default to the current behavior of cmemcache then memcache fallback.

by Jeff Ammons, 14 years ago

Attachment: test.diff added

Test for our proposed fix

comment:6 by Russell Keith-Magee, 14 years ago

Triage Stage: AcceptedDesign decision needed

Erm... there's a test, but no actual fix?

Also - I'm not completely sold on either approach. Specifying a module name in the CACHE_BACKEND setting is a neat idea - provided there is some sort of guarantee that the API for a python memcache backend is always the same. From first inspection, this isn't true (set_many vs set_multi). Subclassing seems like overkill, given that there is a limited number of support classes out there.

Another option that hasn't been floated is to allow pylibmc:// definitions that point to a cache.memcache.PyLibMemcache implementation; that is, we do the subclassing, so end users don't have to.

Also - given that cmemcache is clearly deprecated, so we should also deprecate it's use.

comment:7 by Florian Apolloner, 14 years ago

milestone: 1.2

1.2 is in bug fix mode, removing the milestone…

comment:8 by Russell Keith-Magee, 14 years ago

milestone: 1.2
Triage Stage: Design decision neededAccepted

Putting back to 1.2; there has been some discussion about including a partial fix in 1.2 that would start the deprecation process for cmemcache. That won't close this ticket, but it should be addressed before 1.2 final.

To that end, the mailing list discussion also resolved the design decision: we're going to add a new backend for pylibmc.

comment:9 by Russell Keith-Magee, 14 years ago

milestone: 1.21.3

Deferring this ticket to 1.3; #12427 is tracking the deprecation of cmemcache.

comment:10 by mrts, 14 years ago

Those who need pylibmc support right now can have a look at http://gist.github.com/334682.

comment:11 by jbergstroem, 14 years ago

Will the pylibmc (well, libmemcached) behaviors be exposed? These are very powerful and a game changer in many cases. To mention some of their benefits:

  • consistent hashing
  • switch hash algo to remain compatible with other applications/libraries
  • tweak tcp such as nodelay for a much welcome speed increase

comment:12 by Michael Malone, 14 years ago

Hey guys, just a quick comment from my experiences switching to pylibmc on a (non-django) project I'm working on. The transition was pretty smooth, the only thing I noticed that was slightly different in terms of implementation is that pylibmc raises pylibmc.NotFound if you incr/decr a key that doesn't exist while the other Python clients raise ValueError. I'm pretty sure this will break the Django memcache backend for incr/decr operations.

in reply to:  12 comment:13 by Gabriel Hurley, 14 years ago

Replying to mmalone:

pylibmc raises pylibmc.NotFound if you incr/decr a key that doesn't exist while the other Python clients raise ValueError. I'm pretty sure this will break the Django memcache backend for incr/decr operations.

If necessary, it should be easy enough to catch that and then re-raise a ValueError to be consistent. Django certainly does that to maintain consistency in other places (such as for errors raised by different db backends).

comment:14 by anonymous, 14 years ago

Cc: danger@… added
milestone: 1.32.0

comment:15 by anonymous, 14 years ago

milestone: 2.01.3

comment:16 by elus, 13 years ago

Cc: tomasz.elendt@… added

comment:18 by nmk, 13 years ago

Cc: nikitka@… added

comment:19 by Jannis Leidel, 13 years ago

Has patch: set
Patch needs improvement: set
Summary: [patch] Support new memcached wrapper pylibmcSupport new memcached wrapper pylibmc

A combined patch with the change and tests is preferred.

comment:20 by Russell Keith-Magee, 13 years ago

Resolution: fixed
Status: assignedclosed

(In [15005]) Fixed #11675 -- Added support for the PyLibMC cache library. In order to support this, and clean up some other 1.3 caching additions, this patch also includes some changes to the way caches are defined. This means you can now have multiple caches, in the same way you have multiple databases. A huge thanks to Jacob Burch for the work on the PyLibMC backend, and to Jannis for his work on the cache definition changes.

comment:21 by Jacob, 12 years ago

milestone: 1.3

Milestone 1.3 deleted

Note: See TracTickets for help on using tickets.
Back to Top