使用 Java 与 MySql 的 Unix 套接字连接以避免 JDBC 的 TCP/IP 开销?

发布于 2024-09-24 16:04:39 字数 100 浏览 4 评论 0原文

是否可以使用 Java 建立与 MySql 的 Unix 套接字连接以避免 JDBC 的 TCP/IP 开销?

有谁知道一个图书馆(或者几个图书馆,也许)可以实现这一点?

Is it possible to make a Unix socket connection to MySql with Java to avoid JDBC's TCP/IP overhead?

Does anyone know a library (or a few libraries, perhaps) that makes this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

故事与诗 2024-10-01 16:04:39

此外,mySQL JDBC 驱动程序经过了很长一段时间的打磨,并进行了多项优化调整,例如元数据缓存。我会感到惊讶的是 JDBC 开发人员会在驱动程序中留下大量 TCP/IP 开销。

从 JNI 转向基于 C 的实现可能会比减少 TCP/IP 开销所获得的跳转到本机代码的成本更高。

如果您确实想减少 TCP/IP 开销,您可以考虑使用嵌入式数据库,如 sqlite、derby 或 hypersonic。

Also the mySQL JDBC driver has been polished over a long period and has several optimization tweaks , like caching of metadata. I would be surprised that the JDBC developers would have left a lot of TCP/IP overhead in the driver.

Going over JNI to the C based implementation would probably cost more in jumping to native code than can be gained from reduced TCP/IP overhead.

If you really want to cut out the TCP/IP overhead you might consider using an embedded database like sqlite, derby or hypersonic.

塔塔猫 2024-10-01 16:04:39

JDBC只是一个接口规范。它不会增加任何 TCP/IP 开销。如果存在开销,则是由 JDBC 驱动程序引起的。还有用于内存或文件数据库的 JDBC 驱动程序,并且根本不使用 TCP/IP。

MYSQL JDBC 驱动程序是 JDBC Type 4 驱动程序。这意味着它不使用任何本机代码来访问数据库。如果Java没有访问unix套接字的方法,驱动程序也无法使用它们。[1]

如果你真的想使用unix套接字,也许可以使用MySQL的ODBC驱动程序,它似乎支持unix套接字,然后使用JDBC-ODBC桥从 Java 访问它。

JDBC is only an interface specification. It does not add any TCP/IP overhead. If there is overhead it is caused by the JDBC driver. There are also JDBC drivers for in memory or file databases and don't use TCP/IP at all.

The MYSQL JDBC driver is a JDBC Type 4 driver. That means it does not use any native code to access the database. If Java has no method to access unix sockets, the driver can not use them either.[1]

If you really want to use a unix socket maybe it is possible to use MySQL's ODBC driver which seems to supports unix sockets and then use a JDBC-ODBC bridge to access it from Java.

断念 2024-10-01 16:04:39

您始终可以使用 C 库并自行包装它。我认为它支持 UNIX 套接字。

请问您是如何确定 TCP/IP 开销是一个问题的?您是如何将问题(我认为您遇到的)缩小到这个范围的?

问题只是连接开销而不是数据包开销吗?如果建立连接花费的时间太长,连接池库(例如 Apache commons 中的连接池库)将为您处理该问题。

You could always take the C library and wrap it yourself. I think it supports UNIX sockets.

Can I ask how you've determined the TCP/IP overhead to be an issue? How did you narrow the problem (that I assume you're having) down to that?

Is the problem just the connection overhead as opposed to the packet overhead? If establishing connections is taking too long a connection pooling library (such as the one in Apache commons) would handle that for you.

金橙橙 2024-10-01 16:04:39

只需使用 junixsocket, https://github.com/kohlschutter/junixsocket

它是一个 JNI 支持的库,使用标准 Java Socket API 提供对 AF_UNIX 套接字的访问,并且还附带 MySQL 连接工厂。

Just use junixsocket, https://github.com/kohlschutter/junixsocket

It's a JNI-powered library that provides access to AF_UNIX sockets using the standard Java Socket API, and also comes with a MySQL connection factory.

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