Unix socket connection to MySql with Java to avoid JDBC's TCP/IP overhead?
Is it possible to make a Unix socket connection to MySql with Java to avoid JDBC's TCP/IP overhead?
开发者_C百科Does anyone know a library (or a few libraries, perhaps) that makes this possible?
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, 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.
精彩评论