Code Monkey home page Code Monkey logo

Comments (5)

beef9999 avatar beef9999 commented on May 18, 2024

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 ?

from photonlibos.

GavinRay97 avatar GavinRay97 commented on May 18, 2024

Sure, Node.js is a runtime which uses Chrome V8 engine to allow JavaScript to execute on server.
It provides API's for interacting with network/filesystem etc.

TypeScript is a type-system for JavaScript -- it gets removed at runtime, and compiled into JavaScript.

TypeScript code (with types) --> transpile --> JavaScript code --> Node.js runs JS code --> executes on V8 C++ engine

I mostly use TypeScript as it makes the code easier to read/maintain,
It has no performance impact and disappears after compiling👍


And what is its concurrency modle ? Coroutine ? Async callback ?

It is async callback, the low-level net package in Node.js has event-listeners which fire callback functions when operations happen like data received, socket opened, connection acquired etc.

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 ClientSocket class is created here:
(I made some notes in comments below, for instance right now a static buffer is allocated, I'm not sure if this is supposed to be re-allocated every time)

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)
            })
        })
    }
}

from photonlibos.

beef9999 avatar beef9999 commented on May 18, 2024

I was using my own client to test against your server, in order to reduce variables.

from photonlibos.

GavinRay97 avatar GavinRay97 commented on May 18, 2024

Oh LOL, that makes a more sense doesn't it?

You may want to try commenting out this line
console.count("server received ops")

And see if it makes any difference btw

from photonlibos.

beef9999 avatar beef9999 commented on May 18, 2024

Closed for #97

from photonlibos.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.