Search code examples
google-app-engineapp-engine-ndbquota

Can NDB put_multi help to save write operations?


The GAE document says that

Because each get() or put() operation invokes a separate remote procedure call (RPC), issuing many such calls inside a loop is an inefficient way to process a collection of entities or keys at once.

I don't understand what exactly an inefficient way means. Can it help me to save write operations?


Solution

  • No it can't reduce write operations. However it can save RPCs.

    Think about what is going on. When you call put() the RPC sends data and waits for a response , inside that call is a write to the datastore.

    If a single RPC has a 30ms overhead no matter what it is doing (I am making that number up for the sake of the argument) . and the write takes an additional 20ms. Then each put() call takes 30ms rpc round trip + 20ms for the actual write = 50ms.

    If you perform 100 put() calls in a loop then it will take 5000ms.

    However, if you use put_multi() or db.put([list of entities]) then you will only have a single RPC. This means a single 30ms RPC and 100 * 20ms writes. Which comes out at 2030ms. Ok the numbers aren't accurate and a single RPC with 100 entities will take a little longer than a with just one. But you get the idea.