-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Node.js echo server #96
Comments
It's QPS is 192K, throughput is 750Mb/s. I'd like to update it into my data sheet. I'm not an expert here, please correct me if I'm wrong. So typescript is the project name and nodejs is the language? And what is its concurrency modle ? Coroutine ? Async callback ? |
Sure, Node.js is a runtime which uses Chrome V8 engine to allow JavaScript to execute on server. TypeScript is a type-system for JavaScript -- it gets removed at runtime, and compiled into JavaScript.
I mostly use TypeScript as it makes the code easier to read/maintain,
It is async callback, the low-level The server code is tiny, it just echos back out what it received: function server() {
const server = net.createServer()
server.on("connection", (socket) => {
socket.on("data", (data) => {
console.count("server received ops")
socket.write(data)
})
})
server.listen(flags.PORT, flags.IP, () => {
console.log(`server listening on ${flags.IP}:${flags.PORT}`)
})
} And then the callbacks are registered when the class ClientSocket {
// Should this be re-allocated every operation?
// If so, this needs to be removed, see <---- down below
private static buf: Buffer = Buffer.alloc(flags.BUF_SIZE)
constructor() {
this.socket = new net.Socket()
this.sentOpsTotal = 0
this.receivedOpsTotal = 0
this.sentBytesTotal = 0
this.receivedBytesTotal = 0
this.lastOpStartTime = performance.timeOrigin
}
// Handlers for what should happen when data is received are registered as callbacks here
async connect() {
return new Promise((resolve, reject) => {
this.socket.connect(flags.PORT, flags.IP, () => {
resolve(this)
})
this.socket.on("data", (data) => {
this.receivedOpsTotal++
this.receivedBytesTotal += data.length
// this.socket.write(Buffer.alloc(flags.BUF_SIZE)) <------
this.socket.write(ClientSocket.buf)
this.sentOpsTotal++
this.sentBytesTotal += data.length
this.lastOpStartTime = performance.now()
})
this.socket.on("error", (err) => {
reject(err)
})
})
}
} |
I was using my own client to test against your server, in order to reduce variables. |
Oh LOL, that makes a more sense doesn't it? You may want to try commenting out this line And see if it makes any difference btw |
Closed for #97 |
I wrote this for you, I had forgot you asked about it.
Here is one which takes the same flags as yours, I did not implement streaming because I do not understand much about streaming.
You can run it with
yarn dev:server
andyarn dev:client
after doingyarn install
for dependencies 👍Code_-_Insiders_yeqjIOQJUA.mp4
The text was updated successfully, but these errors were encountered: