Skip to content

Commit e32e282

Browse files
committed
chore: remove and ignore .DS_Store
1 parent 1c6d0a3 commit e32e282

File tree

3 files changed

+55
-55
lines changed

3 files changed

+55
-55
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.DS_Store
1+
**/.DS_Store
22
node_modules
33
target
44
*.node

README.md

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -12,60 +12,6 @@
1212

1313
[API Documents](./docs/modules.md)
1414

15-
## `SO_REUSEPORT` enabled TCP net.Server
16-
17-
The [cluster](https://nodejs.org/dist/latest-v18.x/docs/api/cluster.html) module share server ports by accepting new connections in the primary process and distributing them to worker processes.
18-
19-
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.
20-
21-
For example, the arrow in the image below shows cpu usage of a PM2 primary process which we found in our environment.
22-
23-
![cpu_usage](./resource/cpu_usage.png)
24-
25-
Note that `SO_REUSEPORT` might behave much differently across operating systems. See this [post](https://stackoverflow.com/questions/14388706/how-do-so-reuseaddr-and-so-reuseport-differ) for more information.
26-
27-
### Example
28-
29-
```js
30-
const { createReuseportFd } = require('node-unix-socket');
31-
const { Server, Socket } = require('net');
32-
33-
const port = 8080;
34-
const host = '0.0.0.0';
35-
36-
// create multple servers listening to a same host, port.
37-
for (let i = 0; i < 2; i += 1) {
38-
const fd = createReuseportFd(port, host);
39-
const server = new Server((socket) => {
40-
socket.on('data', (buf) => {
41-
console.log(`server ${i} received:`, buf);
42-
// echo
43-
socket.write(buf);
44-
});
45-
});
46-
47-
server.listen(
48-
{
49-
fd,
50-
},
51-
() => {
52-
console.log(`server ${i} is listening on ${port}`);
53-
}
54-
);
55-
}
56-
57-
setInterval(() => {
58-
const client = new Socket();
59-
client.on('data', (buf) => {
60-
console.log('client received:', buf);
61-
client.destroy();
62-
});
63-
client.connect(port, host, () => {
64-
client.write(Buffer.from('hello'));
65-
});
66-
}, 1000);
67-
```
68-
6915
## Seqpacket Sockets
7016

7117
`SOCK_SEQPACKET` sockets are like `SOCK_DGRAM` sockets and they will keep message boundaries.
@@ -145,6 +91,60 @@ setInterval(() => {
14591
}, 1000);
14692
```
14793

94+
## `SO_REUSEPORT` enabled TCP net.Server
95+
96+
The [cluster](https://nodejs.org/dist/latest-v18.x/docs/api/cluster.html) module share server ports by accepting new connections in the primary process and distributing them to worker processes.
97+
98+
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.
99+
100+
For example, the arrow in the image below shows cpu usage of a PM2 primary process which we found in our environment.
101+
102+
![cpu_usage](./resource/cpu_usage.png)
103+
104+
Note that `SO_REUSEPORT` might behave much differently across operating systems. See this [post](https://stackoverflow.com/questions/14388706/how-do-so-reuseaddr-and-so-reuseport-differ) for more information.
105+
106+
### Example
107+
108+
```js
109+
const { createReuseportFd } = require('node-unix-socket');
110+
const { Server, Socket } = require('net');
111+
112+
const port = 8080;
113+
const host = '0.0.0.0';
114+
115+
// create multple servers listening to a same host, port.
116+
for (let i = 0; i < 2; i += 1) {
117+
const fd = createReuseportFd(port, host);
118+
const server = new Server((socket) => {
119+
socket.on('data', (buf) => {
120+
console.log(`server ${i} received:`, buf);
121+
// echo
122+
socket.write(buf);
123+
});
124+
});
125+
126+
server.listen(
127+
{
128+
fd,
129+
},
130+
() => {
131+
console.log(`server ${i} is listening on ${port}`);
132+
}
133+
);
134+
}
135+
136+
setInterval(() => {
137+
const client = new Socket();
138+
client.on('data', (buf) => {
139+
console.log('client received:', buf);
140+
client.destroy();
141+
});
142+
client.connect(port, host, () => {
143+
client.write(Buffer.from('hello'));
144+
});
145+
}, 1000);
146+
```
147+
148148
## CONTRIBUTING
149149

150150
[CONTRIBUTING.md](./CONTRIBUTING.md)

__test__/.DS_Store

-6 KB
Binary file not shown.

0 commit comments

Comments
 (0)