This is an add-on for OrientDB database to enable UNIX socket connection.
####Reasons for unix socket usage :
- Unix socket is much faster than TCP/IP and less memory demanding.
- Unix socket is better choice when communicating with processes inside the same box
- Support for Nginx unix socket proxying
- Ideal for OrientDB in-memmory database (session storage)
- Docker inter container communication through unix sockets instead of linked containers (linked containers will change IP address after restart)
####Features :
- Zero-copy read/write operations
- Pure Java implementation
- TODO - Unix Domain Socket EPOLL - Async I/O
- Copy jar file from ./build/orientdb/lib to installed OrientDB /lib folder
- In /build/orientdb/config one can find setup example, search for UNIX SOCKET SUPPORT comment under sockets & listeners for an example.
Only parameter to setup inside xml configuration is network.socket.unix which should contain path to socket file. Default is /tmp/orientdb.sock
-
Create empty folder
-
Copy to that folder ./build/demo.js
-
Position to and execute
npm install orientjs
-
Open ./node_modules/orientjs/lib/transport/binary/connection.js in text editor modify createSocket function
from
Connection.prototype.createSocket = function () { var socket = net.createConnection(this.port, this.host); socket.setNoDelay(true); socket.setMaxListeners(100); return socket; };
to
Connection.prototype.createSocket = function () { var socket = null; var isUnix = ['linux','darwin'].indexOf(process.platform) > -1 ; if (this.host.indexOf('unix:') === 0 && isUnix) { var uxPath = this.host.replace('unix:',''); socket = net.createConnection(uxPath); } else { socket = net.createConnection(this.port, this.host); } socket.setNoDelay(true); socket.setMaxListeners(100); return socket; };
-
Whenever OrientDB driver is used inside Node.JS to connect to the unix socket, unix: prefix should be used.
var OrientDB = require('orientjs'); var server = OrientDB({ host: 'unix:/tmp/orientdb.sock', username: 'root', password: 'root' });
-
Start app with command below to check if it is working
node demo
Note:
- File unixsocket.orientdb.jar in ./build folder is built with Java 8. If one have an older version of Java installed, Java sources should be rebuilt with that version.
- Don't forget to include OrientDB jar's from it's lib folder before building.
|
Reference:
- Original project junixsocket
- JNR project part of Java Panama project
|
Performance analysis TCP/IP vs UNIX SOCKET:
|
Credits:
- Unix Domain Sockets in Java (AF_UNIX) junixsocket
That's all folks!