Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
oyyd committed Aug 22, 2017
1 parent 398eea5 commit d22420d
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 9 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ node 6+

## Performance and Benchmark

```
sudo sysctl net.inet.udp.recvspace=4194304
```

## About Multiplexing

- Data that comes later have to wait previous data to be transmited.
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
"test:travis": "jest --coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
"test:watch": "jest --watch",
"test:single": "jest src/kcp/__tests__/packet.spec.js --watch",
"benchmark:udp": "node lib/__tests__/udp.benchmark.js",
"benchmark:encrypt": "node lib/__tests__/encrypt.benchmark.js",
"benchmark:socket": "node lib/__tests__/socket.benchmark.js"
"benchmark:socket": "node --inspect-brk lib/__tests__/socket.benchmark.js"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/socket.benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const testKCPSocket = () => new Promise((resolve) => {
// console.log('msg', msg)
if (msg) {
received += msg.length
console.log('msg.length', msg.length)
// console.log('msg.length', msg.length)
if (received >= DATA_SIZE) {
received -= DATA_SIZE
count += 1
Expand Down
38 changes: 38 additions & 0 deletions src/__tests__/udp.benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import dgram from 'dgram'

function main() {
const s1 = dgram.createSocket('udp4')
const s12 = dgram.createSocket('udp4')
const s2 = dgram.createSocket('udp4')
const TIMES = 4 * 1024

let port = null
let times = 0
let received = 0
let start = 0

s2.on('message', (msg) => {
times += 1
received += msg.length
console.log(`received: ${times} ${received}`)

if (times === TIMES) {
console.log(`${Date.now() - start} elapses`)
}
})

function sendMsg(socket) {
for (let i = 0; i < TIMES; i += 1) {
socket.send(Buffer.allocUnsafe(1400), port)
}
}

s2.bind(() => {
port = s2.address().port
start = Date.now()

sendMsg(s1)
})
}

main()
10 changes: 7 additions & 3 deletions src/kcp/__tests__/packet.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ describe('integration test', () => {
let received = 0

const loop = () => {
console.log('LOOP', Date.now() - p0)
const current = getCurrent()
let d

Expand Down Expand Up @@ -143,15 +144,18 @@ describe('integration test', () => {

if (received === size) {
done()
return
}
}

console.log('before update:', Date.now() - p0)
update(kcp1, current)
console.log('after update:', Date.now() - p0)

setTimeout(loop)
}

setInterval(() => {
process.nextTick(loop)
}, 10)
setInterval(loop, 0)

sendByPackets(kcp1, data)
})
Expand Down
5 changes: 1 addition & 4 deletions src/updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ class Updater {

this.isUpdating = true

// TODO:
setTimeout(() => {
process.nextTick(this.updateTask)
}, 10)
setTimeout(this.updateTask, 0)
}
}

Expand Down

0 comments on commit d22420d

Please sign in to comment.