Skip to content
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

Apache benchmark not working. #55

Closed
tahonaPL opened this issue Oct 24, 2022 · 2 comments
Closed

Apache benchmark not working. #55

tahonaPL opened this issue Oct 24, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@tahonaPL
Copy link

Wanted to test http with ab.

ab -n 1 -c 1 http://localhost:8080/plaintext

using this :

const stringify = require('@stringify')
const http = require('@http')
const process = require('process')

const { createServer, responses } = http
const { sjs, attr } = stringify

const message = 'Hello, World!'
const json = { message }

function spawn (main) {
    if (just.env()['WORKER']) return main()
    const { watch, launch } = process
    const processes = []
    const cpus = parseInt(just.env().CPUS || just.sys.cpus, 10)
    for (let i = 0; i < cpus; i++) {
      just.sys.setenv('WORKER', i)
      //const proc = launch(just.args[0], ['--trace-gc', ...just.args.slice(1)])
      const proc = launch(just.args[0], just.args.slice(1))
      processes.push(proc)
      proc.stats = { user: 0, system: 0 }
    }
    return Promise.all(processes.map(p => watch(p)))
}

class Clock {
    constructor () {
      this.slots = new Map()
    }
  
    unset (callback, repeat = 1000) {
      const current = this.slots.get(repeat)
      if (!current) return
      current.callbacks = current.callbacks.filter(cb => cb !== callback)
      if (!current.callbacks.length) {
        just.clearTimeout(current.timer)
        this.slots.delete(repeat)
      }
    }
  
    set (callback, repeat = 1000) {
      let current = this.slots.get(repeat)
      if (current) {
        current.callbacks.push(callback)
        return
      }
      current = {
        callbacks: [callback],
        timer: just.setInterval(() => current.callbacks.forEach(cb => cb()), repeat)
      }
      this.slots.set(repeat, current)
    }
}

async function main() {
    const sJSON = sjs({ message: attr('string') })

    const server = createServer()
        .get('/plaintext', res => res.text(message))
        .get('/json', res => res.utf8(sJSON(json), responses.json))
        .listen('0.0.0.0', 8080)

    const clock = new Clock()
    clock.set(() => {
        server.update()
    })
}

spawn(main)
    .catch(err => just.error(err.stack))
@tahonaPL
Copy link
Author

tahonaPL commented Nov 2, 2022

@billywhizz ?

@billywhizz billywhizz added the bug Something isn't working label Sep 29, 2023
@Mupli
Copy link

Mupli commented May 10, 2024

I think this is related to limitation of apache benchmark for newer tech : http2 + , websockets

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants