python - ArangoDB 读取超时(读取超时=60)

标签 python docker docker-compose arangodb python-arango

我有一个问题。我正在通过 Docker 使用 ArangoDB enterprise:3.8.6。但不幸的是,我的查询花费的时间超过 30s。 当它失败时,错误是 arangodb HTTPConnectionPool(host='127.0.0.1', port=8529): Read timed out。 (读取超时=60)

  • 我的收藏大约有 4GB,大约 1.2 mio - 收藏中有 90 万份文档。

我怎样才能毫无错误地获得包含所有文档的完整集合?

Python 代码(在我的机器上本地运行)

from arango import ArangoClient

# Initialize the ArangoDB client.
client = ArangoClient()

# Connect to database as  user.
db = client.db(<db>, username=<username>, password=<password>)

cursor = db.aql.execute(f'FOR doc IN students RETURN doc', batch_size=10000)
result = [doc for doc in cursor]

print(result[0])

[OUT]
arangodb HTTPConnectionPool(host='127.0.0.1', port=8529): Read timed out. (read timeout=60)

ArangoDB 的 docker-compose.yml

version: '3.7'

services:
  database:
    container_name: database__arangodb
    image: arangodb/enterprise:3.8.6
    environment:
      - ARANGO_LICENSE_KEY=<key>
      - ARANGO_ROOT_PASSWORD=root
      - ARANGO_CONNECT_TIMEOUT=300
      - ARANGO_READ_TIMEOUT=600
    ports:
      - 8529:8529
    volumes:
      - C:/Users/dataset:/var/lib/arangodb3

我尝试过的

cursor = db.aql.execute('FOR doc IN <Collection> RETURN doc', stream=True)
while cursor.has_more(): # Fetch until nothing is left on the server.
    cursor.fetch()
while not cursor.empty(): # Pop until nothing is left on the cursor.
    cursor.pop()

[OUT] CursorNextError: [HTTP 404][ERR 1600] cursor not found

# A N D 
cursor = db.aql.execute('FOR doc IN <Collection> RETURN doc', stream=True, ttl=3600)
collection =  [doc for doc in cursor]
[OUT] nothing # Runs, runs and runs for more than 1 1/2 hours

什么有效仅适用于 100 个文档

# And that worked
cursor = db.aql.execute(f'FOR doc IN <Collection> LIMIT 100 RETURN doc', stream=True)
collection =  [doc for doc in cursor]

最佳答案

可以增加HTTP客户端的timeout通过使用 custom HTTP client对于 Arango。

默认设置为 here到 60 秒。

from arango.http import HTTPClient


class MyCustomHTTPClient(HTTPClient):
    REQUEST_TIMEOUT = 1000 # Set the timeout you want in seconds here


# Pass an instance of your custom HTTP client to Arango:
client = ArangoClient(
    http_client=MyCustomHTTPClient()
)

关于python - ArangoDB 读取超时(读取超时=60),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71838934/

相关文章:

docker - 问题是我无法从python应用程序连接到scylla节点。我是否需要更改任何scylla.yaml属性?

php - Docker 中的 MySQL 数据库访问被拒绝

docker - 根据环境在Dockerfile中调用不同的命令

python - 有条件地乘法列表python

python - Elasticsearch 查询日期范围不起作用

python - 从 Wayland 下的 xid 获取 GDK Window

docker - Flannels 在 Kubernetes 多节点示例中不起作用

python - Python 中的 getter 和 setter

python - 无法在 docker 容器中安装任何 python 包

docker - Spring Boot Redis 在使用 Redis 时获取连接被拒绝的异常