# GRPC Insert - Broken Pipe and timeouts

**URL:** <https://community.pinecone.io/t/grpc-insert-broken-pipe-and-timeouts/313>\
**Category:** Support\
**Created:** [March 23, 2022, 9:57pm UTC](https://community.pinecone.io/t/grpc-insert-broken-pipe-and-timeouts/313 "2022-03-23T21:57:12Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![ab1](https://avatars.discourse-cdn.com/v4/letter/a/d2c977/32.png) [@ab1](https://community.pinecone.io/u/ab1)\
**Post date:** [March 23, 2022, 9:57pm UTC](https://community.pinecone.io/t/grpc-insert-broken-pipe-and-timeouts/313/1 "2022-03-23T21:57:13Z")

</div>

I am using the GRPC client of pinecone to do inserts. At times it works and at times it doesnt. I am following instructions on [Performance tuning](https://www.pinecone.io/docs/performance-tuning/)

When I try to do inserts, I get following message

Traceback (most recent call last): File “${HOME}/anaconda3/envs/pinecone\_insert/lib/python3.8/site-packages/pinecone/core/grpc/index\_grpc.py”, line 227, in result self.\_delegate.result(timeout=timeout) File “${HOME}/anaconda3/envs/pinecone\_insert/lib/python3.8/site-packages/grpc/\_channel.py”, line 744, in result raise self grpc.\_channel.\_MultiThreadedRendezvous: \<\_MultiThreadedRendezvous of RPC that terminated with: status = StatusCode.UNAVAILABLE details = “Broken pipe” debug\_error\_string = “{“created”:”@1648071646.318306073",“description”:“Error received from peer ipv4:34.127.5.128:443”,“file”:“src/core/lib/surface/call.cc”,“file\_line”:1067,“grpc\_message”:“Broken pipe”,“grpc\_status”:14}" \>  
The above exception was the direct cause of the following exception:  
Traceback (most recent call last): File “upserter.py”, line 55, in [async\_result.result() for async\_result in async\_results] File “upserter.py”, line 55, in [async\_result.result() for async\_result in async\_results] File “${HOME}/anaconda3/envs/pinecone\_insert/lib/python3.8/site-packages/pinecone/core/grpc/index\_grpc.py”, line 229, in result raise PineconeException(e.\_state.debug\_error\_string) from e pinecone.core.exceptions.PineconeException: {“created”:"@1648071646.318306073",“description”:“Error received from peer ipv4:34.127.5.128:443”,“file”:“src/core/lib/surface/call.cc”,“file\_line”:1067,“grpc\_message”:“Broken pipe”,“grpc\_status”:14}

---

<div class="post-metadata">

**Author:** ![rajat](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/rajat/32/3037_2.png) [@rajat](https://community.pinecone.io/u/rajat)\
**Post date:** [March 24, 2022, 3:23pm UTC](https://community.pinecone.io/t/grpc-insert-broken-pipe-and-timeouts/313/2 "2022-03-24T15:23:32Z")

</div>

Hey @ab1 ,

Can you share your upsert code snippet and the index name?  
Also, do you see this only for async upserts?

---

<div class="post-metadata">

**Author:** ![ab1](https://avatars.discourse-cdn.com/v4/letter/a/d2c977/32.png) [@ab1](https://community.pinecone.io/u/ab1)\
**Post date:** [March 24, 2022, 5:09pm UTC](https://community.pinecone.io/t/grpc-insert-broken-pipe-and-timeouts/313/3 "2022-03-24T17:09:07Z")

</div>

```auto
PINECONE_INDEX='--'
VECTOR_COUNT = 100000
VECTOR_DIM = 384
BATCH_SIZE=100
index = pinecone.GRPCIndex(PINECONE_INDEX)
example_data_generator = map(lambda i: (f'id-{i}', [random.random() for _ in range(VECTOR_DIM)]), range(VECTOR_COUNT))
with index:
    async_results = [
        index.upsert(vectors=chunk, async_req=True)
        for chunk in chunks(example_data_generator, batch_size=BATCH_SIZE)
    ]

    # Wait for and retrieve responses (in case of error)
    [async_result.result() for async_result in async_results]te code here

```

I see it only for async upserts. If I dont do async upsert, it doesnt complete the job e.g. for 1M inserts, it only ends up adding 300-350K. With async at times it does all 1M inserts at times it doest.

---

<div class="post-metadata">

**Author:** ![rajat](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/rajat/32/3037_2.png) [@rajat](https://community.pinecone.io/u/rajat)\
**Post date:** [March 24, 2022, 5:11pm UTC](https://community.pinecone.io/t/grpc-insert-broken-pipe-and-timeouts/313/4 "2022-03-24T17:11:56Z")

</div>

I think the non-async behavior is a bit strange. Do you see any error messages at all or is it just a silent failure?

---

<div class="post-metadata">

**Author:** ![rajat](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/rajat/32/3037_2.png) [@rajat](https://community.pinecone.io/u/rajat)\
**Post date:** [March 24, 2022, 6:15pm UTC](https://community.pinecone.io/t/grpc-insert-broken-pipe-and-timeouts/313/5 "2022-03-24T18:15:44Z")

</div>

Hey @ab1, I just used your code to insert a million vectors using both async and non-async upserts.  
So I think it’s likely not a client error. I looked at the logs for your index and looks more like a connection issue to me, also broken pipe errors are a sign of connection issues (either on your or our end). Can you try using a VM in the cloud or maybe a Colab notebook for upserts? that would guarantee a stronger connection and would be good to rule out something like this.

Also, sometimes when you send a lot of requests at once, the index takes a bit (depending on number of requests) to catch up, so you may see all the vectors in the console after a few minutes.

---

<div class="post-metadata">

**Author:** ![ab1](https://avatars.discourse-cdn.com/v4/letter/a/d2c977/32.png) [@ab1](https://community.pinecone.io/u/ab1)\
**Post date:** [March 24, 2022, 8:53pm UTC](https://community.pinecone.io/t/grpc-insert-broken-pipe-and-timeouts/313/6 "2022-03-24T20:53:17Z")

</div>

Following is error message. It times out in pinecone/core/grpc/index\_grpc.py. I have tried this from multiple locations (wifi, wired connection, AWS node, notebook etc.) Still get timeouts. I have tried so far 15-20 times and only once I have been able to to get to 1M. Otherwise it timesout much before that. Do you have any suggestions for error handling / retrys?

````auto
  File "upserter.py", line 47, in insert_data_for_chunk
    retrieved_responses += [async_result.result()]
  File "${HOME}/anaconda3/envs/pinecone_insert/lib/python3.8/site-packages/pinecone/core/grpc/index_grpc.py", line 227, in result
    self._delegate.result(timeout=timeout)
TypeError: result() got an unexpected keyword argument 'timeout'```
````

---

<div class="post-metadata">

**Author:** ![rajat](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/rajat/32/3037_2.png) [@rajat](https://community.pinecone.io/u/rajat)\
**Post date:** [March 28, 2022, 3:47pm UTC](https://community.pinecone.io/t/grpc-insert-broken-pipe-and-timeouts/313/7 "2022-03-28T15:47:25Z")

</div>

Hey @ab1,  
You don’t need to store the results really, just calling .result() on them would be fine in knowing if there’s an error.  
May I suggest you another approach to make the upserts faster? Instead of using async, you can try using multiple instances of the client. You can create a multiprocessing pool in python and have each of them perform upserts independently. This would be faster. However, if you don’t have enough pods on your index, this may cause some timeouts as the index won’t be able to keep up, hence we have to be a little conservative with the number of processes.

Here’s an example:

```auto
import multiprocessing
import os
import pinecone 
import uuid
import numpy as np

def upsert(data,index_name,batch):
    key = 'API_KEY'
    pinecone.init(api_key=key,environment='ENV')
    index = pinecone.GRPCIndex(index_name)
    index.describe_index_stats()
    def chunker(sqd,size):
        return (seq[pos:pos + size] for pos in range(0, len(seq), size))
    for chunk in chunker(data,batch):
        index.upsert(vectors=chunk)

if __name__ ==" __main__":
    mgr = multiprocessing.Manager()
    num_processes = 6
    for i in range(num_processes):
        multiprocessing.Process(target=upsert,args=(data,index_name,batch_size)

```

---

<div class="post-metadata">

**Author:** ![ab1](https://avatars.discourse-cdn.com/v4/letter/a/d2c977/32.png) [@ab1](https://community.pinecone.io/u/ab1)\
**Post date:** [March 28, 2022, 7:41pm UTC](https://community.pinecone.io/t/grpc-insert-broken-pipe-and-timeouts/313/8 "2022-03-28T19:41:30Z")

</div>

Let me give this a shot. Will keep you posted in terms of how it goes. I am going to try with 5+ pods to start with.

---

<div class="post-metadata">

**Author:** ![rajat](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/rajat/32/3037_2.png) [@rajat](https://community.pinecone.io/u/rajat)\
**Post date:** [March 28, 2022, 8:29pm UTC](https://community.pinecone.io/t/grpc-insert-broken-pipe-and-timeouts/313/9 "2022-03-28T20:29:29Z")

</div>

Sounds good. Also would be great to know more about where you are calling it from, ec2 or notebook or local, from which region, etc.

---

<div class="post-metadata">

**Author:** ![ab1](https://avatars.discourse-cdn.com/v4/letter/a/d2c977/32.png) [@ab1](https://community.pinecone.io/u/ab1)\
**Post date:** [March 31, 2022, 11:00pm UTC](https://community.pinecone.io/t/grpc-insert-broken-pipe-and-timeouts/313/10 "2022-03-31T23:00:48Z")

</div>

The above approach worked with little bit of finetuning. Getting good upsert rates. Doing inserts via ec2. Thanks for your help. Will let you know if any issues. We can mark the issue closed

---

<div class="post-metadata">

**Author:** ![rajat](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/rajat/32/3037_2.png) [@rajat](https://community.pinecone.io/u/rajat)\
**Post date:** [April 1, 2022, 12:39am UTC](https://community.pinecone.io/t/grpc-insert-broken-pipe-and-timeouts/313/11 "2022-04-01T00:39:13Z")

</div>

Great, if it would help we have a [Spark connector](https://github.com/pinecone-io/spark-pinecone) that you can use next time you want to perform some higher volume upserts.

---

<div class="post-metadata">

**Author:** ![ab1](https://avatars.discourse-cdn.com/v4/letter/a/d2c977/32.png) [@ab1](https://community.pinecone.io/u/ab1)\
**Post date:** [April 1, 2022, 12:50am UTC](https://community.pinecone.io/t/grpc-insert-broken-pipe-and-timeouts/313/12 "2022-04-01T00:50:25Z")

</div>

Great… will give it a try
