# How to insert batch data faster with mutation?

**URL:** <https://discuss.dgraph.io/t/how-to-insert-batch-data-faster-with-mutation/16483>\
**Category:** Dgraph\
**Tags:** kind:question\
**Created:** [January 7, 2022, 8:27am UTC](https://discuss.dgraph.io/t/how-to-insert-batch-data-faster-with-mutation/16483 "2022-01-07T08:27:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Echo](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/echo/32/9403_2.png) [@Echo](https://discuss.dgraph.io/u/Echo)\
**Post date:** [January 7, 2022, 8:27am UTC](https://discuss.dgraph.io/t/how-to-insert-batch-data-faster-with-mutation/16483/1 "2022-01-07T08:27:45Z")

</div>

## What I want to do

I’m using this kind of DQL with a python client to insert batch data. But it’s a bit slow, about 25s for 1000 triples. I’d like to ask if there’re faster ways to do it? Thank you very much~

```auto
nquad = "
<0x01> <friend> <0x02> .
<0x01> <friend> <0x03> .
<0x01> <friend> <0x03> ."

txn = self.client.txn()
mutation = txn.create_mutation(set_nquads=nquad)
request = txn.create_request(mutations=[mutation], commit_now=True)
txn.do_request(request)

```

## Dgraph metadata

> **dgraph version**
>
> The version of the dgraph I am using is v21.03.2.

---

<div class="post-metadata">

**Author:** ![iluminae](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/iluminae/32/7367_2.png) [@iluminae](https://discuss.dgraph.io/u/iluminae)\
**Post date:** [January 7, 2022, 12:44pm UTC](https://discuss.dgraph.io/t/how-to-insert-batch-data-faster-with-mutation/16483/2 "2022-01-07T12:44:31Z")

</div>

Try it with the live loader and compare speeds - if it’s better you can look into why since it’s using the same API.

If it’s the same-ish then you will probably want to profile your system.

---

<div class="post-metadata">

**Author:** ![Echo](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/echo/32/9403_2.png) [@Echo](https://discuss.dgraph.io/u/Echo)\
**Post date:** [January 9, 2022, 8:29am UTC](https://discuss.dgraph.io/t/how-to-insert-batch-data-faster-with-mutation/16483/3 "2022-01-09T08:29:44Z")

</div>

Hey, I checked up on live loader before, but since I have to use Python client, I’m not sure that I can use it. I’m thinking to use async functions to execute it concurrently. Is multithreads supported in Python clients? I didn’t find this in the documents.

Thank you very much~

---

<div class="post-metadata">

**Author:** ![iluminae](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/iluminae/32/7367_2.png) [@iluminae](https://discuss.dgraph.io/u/iluminae)\
**Post date:** [January 9, 2022, 2:53pm UTC](https://discuss.dgraph.io/t/how-to-insert-batch-data-faster-with-mutation/16483/4 "2022-01-09T14:53:51Z")

</div>

I was not suggesting to use the live loader instead of python to build your application, just to identify if your dgraph instance (which I assume you are running yourself) is the cause of the slowness or your program.

If the live loader is faster you know there is something you can do in your program to make it faster - because both the live loader and the python bindings use the exact same gRPC interface to dgraph. If the live loader is not much faster, you should look at properly resourcing your dgraph instance.

---

<div class="post-metadata">

**Author:** ![Echo](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/echo/32/9403_2.png) [@Echo](https://discuss.dgraph.io/u/Echo)\
**Post date:** [January 10, 2022, 2:33am UTC](https://discuss.dgraph.io/t/how-to-insert-batch-data-faster-with-mutation/16483/5 "2022-01-10T02:33:50Z")

</div>

OK, I will try this, thank you~.

But I have another question. I’m using a distributed framework called ray to accelerate it. But it seems that when I use dgraph in my code, it doesn’t run concurrently, the tasks are lined up. So I’d like to ask if there’s some restriction of the client connection?

---

<div class="post-metadata">

**Author:** ![iluminae](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/iluminae/32/7367_2.png) [@iluminae](https://discuss.dgraph.io/u/iluminae)\
**Post date:** [January 10, 2022, 5:34am UTC](https://discuss.dgraph.io/t/how-to-insert-batch-data-faster-with-mutation/16483/6 "2022-01-10T05:34:23Z")

</div>

I don’t know how Ray does it’s thing (maybe just a multiprocess orchestrator?) - and I have never seriously used python for anything, so could not help you there. The bindings are pretty thin around the gRPC bindings (if anything like the go dgraph bindings, of which I am far more familiar) so I doubt there is much in there that could be interfering - that is conjecture, though.

Ok maybe not a very helpful reply - sorry!
