mysql 连接在 3000 后失败+尝试

发布于 2024-08-13 06:38:57 字数 903 浏览 8 评论 0原文

我只是在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

单身狗的梦 2024-08-20 06:38:57

TCP 连接占用内核内存,即使在关闭之后也是如此。如果你说:

netstat -na |grep WAIT

我想你会发现这3000个连接中的大部分仍然处于TIME_WAIT状态,这个状态一般会持续120秒。根据您的情况,它可能会优化为较低的值,但仍然很长,例如 30 秒。如果您的程序能够在此时建立足够的连接,则您可以在为跟踪 TCP 连接而保留的内存不足的情况下运行内核。

TCP connections take kernel memory, even after they are closed. If you say:

netstat -na |grep WAIT

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文