Unix socket connection to MySql with Java to avoid JDBC's TCP/IP overhead?

試著忘記壹切 提交于 2019-12-05 07:59:45

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.

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.

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.

Just use junixsocket, http://code.google.com/p/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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!