性能调优
本节提供了一些有关如何获得最佳性能的提示。
基本性能清单
切换到云环境。例如:EC2、GCE、Google Colab、GCP AI Platform Notebook或[SageMaker Notebook](https://docs.aws.amazon.com/sagemaker/latest/dg/nbi)。如果您遇到上传缓慢或查询延迟高的问题,可能是因为您从家庭网络访问Pinecone。
将应用程序和Pinecone服务部署在同一地区。对于免费计划的用户,Pinecone在GCP US-West(俄勒冈州)运行。联系我们如果您需要专用部署。
Reuse connections. We recommend you reuse the same
pinecone.Index()
instance when you are upserting and querying the same index.在已知的限制内运营。
如何提高吞吐量
要提高吞吐量(QPS),请增加索引的副本数量。
示例
The following example increases the number of replicas for example-index
to 4.
下面分别是Python、JavaScript和Curl代码
pinecone.configure_index("example-index", replicas=4)
await pinecone.configureIndex("example-index", { replicas: 4 });
curl -i -X PATCH https://controller.us-west1-gcp.pinecone.io/databases/example-index \
-H 'Api-Key: YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"replicas": 4
}'
有关更多详细信息,请参见configure_index API 参考。
使用 gRPC 客户端以获得更高的 upsert 速度
Pinecone提供了标准客户端的gRPC版本(安装),可为多Pod索引提供更高的upsert速度。
连接到gRPC客户端的索引:
Python
index = pinecone.GRPCIndex("index-name")
使用gRPC客户端的upsert、query、fetch和delete语法与标准客户端相同。
我们建议您使用并行upsert以获得最佳性能。
Python
index = pinecone.GRPCIndex('example-index')
def chunker(seq, batch_size):
return (seq[pos:pos + batch_size] for pos in range(0, len(seq), batch_size))
async_results = [
index.upsert(vectors=chunk, async_req=True)
for chunk in chunker(data, batch_size=100)
]
# Wait for and retrieve responses (in case of error)
[async_result.result() for async_result in async_results]
我们建议您仅在多Pod索引中使用gRPC客户端。标准客户端和gRPC客户端在单Pod索引中的性能相似。
使用gRPC索引进行upsert时,可能会更快地获得写入限制。如果您经常看到这种情况,我们建议您在upsert时使用回退算法。
Pinecone是线程安全的,因此您可以并行启动多个读取请求和多个写入请求。启动多个请求可以帮助提高吞吐量。但是,不能并行执行读取和写入,因此大批量写入可能会影响查询延迟,反之亦然。
最近更新:4个月前