just icon indicating copy to clipboard operation
just copied to clipboard

Apache benchmark not working.

Open tahonaPL opened this issue 2 years ago • 2 comments

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 avatar Oct 24 '22 17:10 tahonaPL

@billywhizz ?

tahonaPL avatar Nov 02 '22 12:11 tahonaPL

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

Mupli avatar May 10 '24 07:05 Mupli