[英]Neo4j connection error as more concurrent users connect
A web server I run has suddenly experienced a 2000% increase in traffic.我运行的 Web 服务器突然经历了 2000% 的流量增加。 Everything was working fine before this increase.
在这次增加之前,一切都很好。 However, now I'm seeing the following error after a few hours (unsure how long, but within 5 hours) of heavy traffic and then fail constantly after that.
但是,现在我在交通繁忙的几个小时(不确定多长时间,但在 5 小时内)后看到以下错误,然后在此之后不断失败。 Like connections are not being closed or something.
就像连接没有被关闭之类的。
db = GraphDatabase.driver("bolt://localhost:MYPORTNO", auth=basic_auth(DATABASE_USERNAME, DATABASE_PASSWORD, encrypted=False)
File "/home/ubuntu/api/env/lib/python3.6/site-packages/neo4j/__init__.py", line 120, in driver
return Driver(uri, **config)
File "/home/ubuntu/api/env/lib/python3.6/site-packages/neo4j/__init__.py", line 161, in __new__
return subclass(uri, **config)
File "/home/ubuntu/api/env/lib/python3.6/site-packages/neo4j/__init__.py", line 235, in __new__
pool.release(pool.acquire())
File "/home/ubuntu/api/env/lib/python3.6/site-packages/neobolt/direct.py", line 715, in acquire
return self.acquire_direct(self.address)
File "/home/ubuntu/api/env/lib/python3.6/site-packages/neobolt/direct.py", line 608, in acquire_direct
connection = self.connector(address, error_handler=self.connection_error_handler)
File "/home/ubuntu/api/env/lib/python3.6/site-packages/neo4j/__init__.py", line 232, in connector
return connect(address, **dict(config, **kwargs))
File "/home/ubuntu/api/env/lib/python3.6/site-packages/neobolt/direct.py", line 972, in connect
raise last_error
File "/home/ubuntu/api/env/lib/python3.6/site-packages/neobolt/direct.py", line 962, in connect
s = _connect(resolved_address, **config)
File "/home/ubuntu/api/env/lib/python3.6/site-packages/neobolt/direct.py", line 843, in _connect
raise ServiceUnavailable("Failed to establish connection to {!r} (reason {})".format(resolved_address, error))
neobolt.exceptions.ServiceUnavailable: Failed to establish connection to ('127.0.0.1', MYPORTNO) (reason [Errno 111] Connection refused)
If I restart apache it works again, so currently as a bandaid, I'm doing that on a cron job every few hours, but that only seems to partially work.如果我重新启动 apache,它会再次工作,所以目前作为创可贴,我每隔几个小时就会在 cron 工作中这样做,但这似乎只是部分工作。
I increased the page cache and heap calculating according to this article .我根据这篇文章增加了页面缓存和堆计算。
I increased the Open Files Limit from the default 1024 to 50000.我将打开文件限制从默认的 1024 增加到 50000。
I doubled the server spec.我将服务器规格翻了一番。
Structurally I create a database driver instance in a config file:从结构上讲,我在配置文件中创建了一个数据库驱动程序实例:
Config file:配置文件:
db = None
def getDB():
global db
if not db:
db = GraphDatabase.driver("bolt://localhost:XXXXXX", auth=basic_auth(DATABASE_USERNAME, DATABASE_PASSWORD), encrypted=False)
return db
I can then make queries in my module files as follows.然后我可以在我的模块文件中进行查询,如下所示。 I believe the following syntax properly manages connections being opened and closed due to the
with
statement, and so shouldn't leave open connections:我相信以下语法可以正确管理由于
with
语句而打开和关闭的连接,因此不应保留打开的连接:
Module file:模块文件:
db = config.getDB()
with db.session() as s:
with s.begin_transaction() as tx:
tx.run("the cypher", {the params})
I am also seeing the following error in the logs, although I'm not sure they are directly related.我还在日志中看到以下错误,尽管我不确定它们是否直接相关。
ValueError: filedescriptor out of range in select()
Does anyone know what is causing this or how to fix it please?有谁知道是什么导致了这个或如何解决它? Thanks!
谢谢!
Turns out that I had a cron job that was running every 10 minutes and was leaving the driver instance open each time.原来我有一个 cron 作业,它每 10 分钟运行一次,并且每次都让驱动程序实例保持打开状态。 Schoolboy error.
小学生错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.