mysql 连接在 3000 后失败+尝试
我只是在 Prolog 中测试一个小脚本来检查 MySQL 连接的完整性。在建立大约 3000 多个连接后,连接随机失败。 MySQL服务器对连接数有限制吗
:-dynamic db_connection/1.
sanity_check_open_db:-
odbc_connect('myDSN', _,
[ user(bob),
password(pop),
alias(myDSN),
open(once)
]),
( db_connection(_),
retractall(db_connection(_))
; assert(db_connection(myDSN))).
sanity_chec_close:-
( db_connection(C),
odbc_disconnect(C),
retractall(db_connection(C))
; write('Error: No connection opened to close')).
sanity_check_open_close(10000).
sanity_check_open_close(N):-
format(atom(C),'~wth Iteration~n',[N]),
write(C),
sanity_check_open_db,
sanity_chec_close,
N1 is N + 1,!,
sanity_check_open_close(N1).
I was just testing a small script in Prolog to sanity check the MySQL connection. The connection fails randomly, after making around 3000+ connections. Is there any limitation in MySQL Server for number of connections
:-dynamic db_connection/1.
sanity_check_open_db:-
odbc_connect('myDSN', _,
[ user(bob),
password(pop),
alias(myDSN),
open(once)
]),
( db_connection(_),
retractall(db_connection(_))
; assert(db_connection(myDSN))).
sanity_chec_close:-
( db_connection(C),
odbc_disconnect(C),
retractall(db_connection(C))
; write('Error: No connection opened to close')).
sanity_check_open_close(10000).
sanity_check_open_close(N):-
format(atom(C),'~wth Iteration~n',[N]),
write(C),
sanity_check_open_db,
sanity_chec_close,
N1 is N + 1,!,
sanity_check_open_close(N1).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
TCP 连接占用内核内存,即使在关闭之后也是如此。如果你说:
我想你会发现这3000个连接中的大部分仍然处于TIME_WAIT状态,这个状态一般会持续120秒。根据您的情况,它可能会优化为较低的值,但仍然很长,例如 30 秒。如果您的程序能够在此时建立足够的连接,则您可以在为跟踪 TCP 连接而保留的内存不足的情况下运行内核。
TCP connections take kernel memory, even after they are closed. If you say:
I think you'll find that most of those 3000 connections are still in the TIME_WAIT state, which typically lasts 120 seconds. It might be optimized to a lower value in your case, but still quite long, like 30 seconds. If your program can make enough connections in that time, you can run the kernel out of memory reserved for keeping track of TCP connections.