Skip to content

Commit

Permalink
支持带宽测试
Browse files Browse the repository at this point in the history
  • Loading branch information
bangbang93 committed Sep 18, 2021
1 parent 20384c3 commit 61bedfd
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
17 changes: 9 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@types/bluebird": "^3.5.27",
"@types/colors": "^1.2.1",
"@types/dotenv": "^6.1.1",
"@types/express": "^4.17.0",
"@types/express": "^4.17.13",
"@types/fs-extra": "^8.0.0",
"@types/lodash": "^4.14.172",
"@types/morgan": "^1.7.36",
Expand All @@ -48,7 +48,7 @@
"@typescript-eslint/parser": "^4.28.5",
"eslint": "^7.32.0",
"ts-node": "^8.3.0",
"typescript": "^3.8.3"
"typescript": "^4.4.3"
},
"npm": {
"publish": false
Expand Down
4 changes: 3 additions & 1 deletion src/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {dirname, join, sep} from 'path'
import * as ProgressBar from 'progress'
import {createInterface} from 'readline'
import * as io from 'socket.io-client'
import MeasureRoute from './measure.route'
import morgan = require('morgan')
import ms = require('ms')
import NextFunction = express.NextFunction
Expand Down Expand Up @@ -141,6 +142,7 @@ export class Cluster {
return next(err)
}
})
app.use('/measure', MeasureRoute)
this.server = createServer(app)

return this.server
Expand Down Expand Up @@ -278,7 +280,7 @@ export class Cluster {
resolve()
this.keepAliveInterval = setTimeout(this._keepAlive.bind(this), ms('1m'))
})
}).timeout(ms('2m'), 'enable request timeout')
}).timeout(ms('5m'), '节点注册超时')
}

private async _keepAlive(): Promise<void> {
Expand Down
17 changes: 17 additions & 0 deletions src/measure.route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import express = require('express')

const router = express.Router()

const MeasureRoute = router

router.get('/:size(\\d+)', (req, res) => {
if (req.get('x-openbmclapi-secret') !== process.env.CLUSTER_SECRET) {
return res.sendStatus(403)
}
const size = parseInt(req.params.size, 10)
if (isNaN(size) || size > 200) return res.sendStatus(400)
const buffer = Buffer.alloc(size * 1024 * 1024)
res.send(buffer)
})

export default MeasureRoute

0 comments on commit 61bedfd

Please sign in to comment.