Skip to content

Support saving of entities to memcache in putMulti() #58

@trakhimenok

Description

@trakhimenok

If I got it right currently entities are not stored to memcache on Put().

Suppose we run in transaction and need to update some entities. Then current execution order is:

  1. User code calss nds.RunInTransaction()
  2. Get entity by key from datastore (not stored to memcache)
  3. Change entities
  4. User code calls nds.PutMulti() with transactional context
  5. nds.putMulti() add items to tx.lockMemcacheItems (memcache not changed)
  6. nds.putMulti() call datastorePutMulti()
  7. nds.putMulti() executes deferrer that removes from memcache tx.lockMemcacheItems.

First of all it's not clear why we create lockItem() at line 129 as it seems it is not used further in current implementation.

Second just removing items from memcache results in unnecessary paid Get() operation on following request while potentially results could be retrieved from the "free" memcache. For example I have a chat application and whenever user writes to the bot and bot sends response I do following:

  1. On request Chat entity is retrieved outside of transaction
  2. On response Chat entity updated within transaction (if state changed)
    Currently the first Get() is not leveraging memcache with always a miss. This increases response time & costs.

So the suggestion is:

  1. Before putting nds should try to lock items in memcache.
  2. If previous pre-put locks was successful nds tries to put items to memcaches using CAS.
  3. If lock or putting to memcache failed try delete from memcache as currently.
  4. Not related improvement: If delete from memcache failed create a deferred task for removing items from memcache. That could mitigate temporarily memcache unavailability.

I know caching is hard to get right and probably I'm missing something.

edit: fixed urls to permalinks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions