https://github.com/bytedance/node-unix-socket
Unix dgram, seqpacket, etc binding for Node.js.
Science Score: 26.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (7.2%) to scientific vocabulary
Keywords
Keywords from Contributors
Repository
Unix dgram, seqpacket, etc binding for Node.js.
Basic Info
- Host: GitHub
- Owner: bytedance
- License: mit
- Language: Rust
- Default Branch: master
- Homepage: https://bytedance.github.io/node-unix-socket/
- Size: 409 KB
Statistics
- Stars: 62
- Watchers: 4
- Forks: 0
- Open Issues: 4
- Releases: 12
Topics
Metadata Files
README.md
node-unix-socket
node-unix-socket allows you to use some nonblocking unix sockets that are currently not supported by Node.js native modules, including:
- unix seqpacket(
SOCK_SEQPACKET) sockets - unix datagram(
SOCK_DGRAM) sockets - Using
SO_REUSEPORTenabled TCP net.Server
node-unix-socket is a napi-rs based Node.js addons and:
- This lib bases on n-api and is pre-compiled so that it doesn't require compilation environments if yours is pre-built supported.
- This lib won't introduce any other asynchronous runtimes as it uses libuv inside Node.js.
We use SOCK_SEQPACKET sockets for in our internal APM.
Tested Platforms & Node.js
|Platform|Node.js|DgramSocket|Seqpacket| |---|---|---|---| |x64 Linux|12 + LTS|✅|✅| |x64 Darwin|12 + LTS|✅|| |aarch64 Darwin|12 + LTS|✅||
Installation
npm i node-unix-socket
API Documents
Seqpacket Sockets
SOCK_SEQPACKET sockets are like SOCK_STREAM sockets while they keep message boundaries.
Note that SOCK_SEQPACKET sockets don't work on MacOS.
Example
```js const { SeqpacketServer, SeqpacketSocket } = require('node-unix-socket'); const os = require('os'); const path = require('path'); const fs = require('fs');
const bindPath = path.resolve(os.tmpdir(), './my_seqpacket.sock');
try { fs.unlinkSync(bindPath); } catch (e) {}
const server = new SeqpacketServer(); server.listen(bindPath); server.on('connection', (socket) => { socket.on('data', (buf) => { console.log('received', buf.toString()); }); });
const client = new SeqpacketSocket(); client.connect(bindPath, () => { const data = ['hello, ', 'w', 'o', 'r', 'l', 'd'];
for (const str of data) { client.write(Buffer.from(str)); } client.end(); }); ```
Dgram Sockets
Example
```js const { DgramSocket } = require('node-unix-socket'); const os = require('os'); const path = require('path'); const fs = require('fs');
const path1 = path.resolve(os.tmpdir(), './mydgram1.sock'); const path2 = path.resolve(os.tmpdir(), './mydgram2.sock');
try { fs.unlinkSync(path1); fs.unlinkSync(path2); } catch (err) {}
const socket1 = new DgramSocket(); const socket2 = new DgramSocket();
socket1.bind(path1); socket2.bind(path2);
socket2.on('data', (data, remoteAddr) => {
console.log(socket2 received: ${data.toString()});
// echo
socket2.sendTo(data, 0, data.length, remoteAddr);
});
socket1.on('data', (data) => {
console.log(socket1 received: ${data.toString()});
});
setInterval(() => { const buf = Buffer.from('hello'); socket1.sendTo(buf, 0, buf.length, path2); }, 1000); ```
SO_REUSEPORT enabled TCP net.Server
The cluster module share server ports by accepting new connections in the primary process and distributing them to worker processes.
With SO_REUSEPORT, sockets will be distributed by kernel instead, and which should be more performant especially for scenario of having a lot of short-lived connections.
For example, the arrow in the image below shows cpu usage of a PM2 primary process which we found in our environment.

Note that SO_REUSEPORT might behave much differently across operating systems. See this post for more information.
Example
```js const { createReuseportFd } = require('node-unix-socket'); const { Server, Socket } = require('net');
const port = 8080; const host = '0.0.0.0';
// create multple servers listening to a same host, port.
for (let i = 0; i < 2; i += 1) {
const fd = createReuseportFd(port, host);
const server = new Server((socket) => {
socket.on('data', (buf) => {
console.log(server ${i} received:, buf);
// echo
socket.write(buf);
});
});
server.listen(
{
fd,
},
() => {
console.log(server ${i} is listening on ${port});
}
);
}
setInterval(() => { const client = new Socket(); client.on('data', (buf) => { console.log('client received:', buf); client.destroy(); }); client.connect(port, host, () => { client.write(Buffer.from('hello')); }); }, 1000); ```
CONTRIBUTING
Development
- Setup rust and Node.js.
- Modify the code.
npm run build && npm run test
LICENSE
MIT
Owner
- Name: Bytedance Inc.
- Login: bytedance
- Kind: organization
- Location: Singapore
- Website: https://opensource.bytedance.com
- Twitter: ByteDanceOSS
- Repositories: 255
- Profile: https://github.com/bytedance
GitHub Events
Total
- Create event: 3
- Issues event: 1
- Release event: 2
- Watch event: 11
- Issue comment event: 8
- Push event: 15
- Pull request event: 5
Last Year
- Create event: 3
- Issues event: 1
- Release event: 2
- Watch event: 11
- Issue comment event: 8
- Push event: 15
- Pull request event: 5
Committers
Last synced: 9 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Ouyang Yadong | o****h@g****m | 75 |
| dependabot[bot] | 4****] | 8 |
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 4
- Total pull requests: 34
- Average time to close issues: over 1 year
- Average time to close pull requests: about 22 hours
- Total issue authors: 4
- Total pull request authors: 2
- Average comments per issue: 1.0
- Average comments per pull request: 0.03
- Merged pull requests: 33
- Bot issues: 0
- Bot pull requests: 9
Past Year
- Issues: 1
- Pull requests: 3
- Average time to close issues: N/A
- Average time to close pull requests: about 11 hours
- Issue authors: 1
- Pull request authors: 1
- Average comments per issue: 0.0
- Average comments per pull request: 0.0
- Merged pull requests: 3
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- oyyd (1)
- albassort (1)
- denyaalt (1)
- Shonke (1)
Pull Request Authors
- oyyd (28)
- dependabot[bot] (8)
Top Labels
Issue Labels
Pull Request Labels
Dependencies
- libc 0.2.123
- napi 2.2.0
- napi-derive 2.2.0
- nix 0.23
- uv-sys 0.1
- 159 dependencies
- @napi-rs/cli ^2.6.2 development
- @types/jest ^27.5.0 development
- @types/node ^17.0.31 development
- jest ^27.5.1 development
- ts-jest ^27.1.4 development
- typedoc ^0.22.15 development
- typescript ^4.6.3 development
- 352 dependencies
- actions-rs/toolchain v1 composite
- actions/cache v2 composite
- actions/cache v3 composite
- actions/checkout v3 composite
- actions/download-artifact v3 composite
- actions/setup-node v3 composite
- actions/upload-artifact v2 composite
- addnab/docker-run-action v3 composite
- mcr.microsoft.com/vscode/devcontainers/javascript-node 0-${VARIANT} build