Hi, I’m trying to use a distributed framework and async function to insert the data to dgraph concurrently, and I used pagination to split the data.
The insert code is like this:
def do_update(self, nquad: str): try: txn = self.client.txn() mutation = txn.create_mutation(set_nquads=nquad) request = txn.create_request(mutations=[mutation], commit_now=True) txn.do_request(request) txn.discard() except Exception as e: print(e) def dgraph_code(): do_update(nquad) async def async_function(): loop = asyncio.get_running_loop() for _ in range(5): futures.append(loop.run_in_executor(None, dgraph_code)) await asyncio.gather(*futures) if __name__ == '__main__': loop = asyncio.get_event_loop() loop.run_until_complete(async_function())
I had 5 threads running at the same time, but I got the result as:
The lengths of insert data are all the same, so it’s supposed to be the same running time, but it seems all lined up ( it’s supposed to be 5 seconds for each round).
Does anyone know why is it and how to fix it? Thank you very much!
The version of the dgraph I am using is v21.03.2.