xk6-amqp icon indicating copy to clipboard operation
xk6-amqp copied to clipboard

Use event loop

Open mstoykov opened this issue 3 years ago • 5 comments

This extension does make asynchronous use of the runtime which leads to panics as shown in #6 .

In the past I did some changes to make it better but those were never commited as were either using unstable APIs or were quite bad.

The latest one uses an early version of what is currently the event loop in k6.

I would argue that the API likely need changes as well, but at least moving to using the event loop will stop the panics and make it usable.

mstoykov avatar Jul 20 '22 11:07 mstoykov

Hi, Stoykov

I used the following script from eventloop branch with the latest version of go(v1.18.3) and k6(v0.33.0) and it worked.

import { sleep } from "k6";
import Amqp from 'k6/x/amqp';
import Queue from 'k6/x/amqp/queue';

export default function() {
  console.log("K6 amqp extension enabled, version: " + Amqp.version)
  const url = "amqp://guest:guest@localhost:5672/"
  Amqp.start({
    connection_url: url
  })
  console.log("Connection opened: " + url)

  const queueName = 'K6 general'

  Queue.declare({
    name: queueName,
    // durable: false,
    // delete_when_unused: false,
    // exclusive: false,
    // no_wait: false,
    // args: null
  })

  console.log(queueName + " queue is ready")


  var o;
  var i = 0;
  const listener = function(data) {
    console.log(`received data by VU ${__VU}, ITER ${__ITER}: ${data} $i = ${i} `)
    i++
  }

  o = Amqp.listen({
    queue_name: queueName,
    listener: listener,
    auto_ack: true,
  })
  setTimeout(() => {
    console.log("stopping", __VU, __ITER);
    o.stop();
  }, 7000)


  var p = Amqp.publish({
    queue_name: queueName,
    body: "Ping from k6 vu: " + __VU + ", iter:" + __ITER,
  })

  p.then(() => {
    console.log("then resolved")
    sleep(2)
    Amqp.publish({
      queue_name: queueName,
      body: "Second ping from k6 vu: " + __VU + ", iter:" + __ITER,
    }).then(() => { console.log("second send resolved") })
  }, (e) => {
    console.log("reject" + e);
  })
}

NivedithaUdatha avatar Jul 26 '22 06:07 NivedithaUdatha

@NivedithaUdatha are you confirming that the branch works? Because I already knew it works with that example ;).

But the whole branch needs an upgrade and I kind of find the API not very javascripty - which is why it isn't just merged but this issue was opened.

Thanks for the feedback though :bow:

mstoykov avatar Jul 26 '22 13:07 mstoykov

I'm currently looking at upgrading to the latest Module API as well.

javaducky avatar Jul 26 '22 13:07 javaducky

Hello @javaducky @mstoykov !

Is there any chance we could see this branch merged into main?

Thank you!

joaovsc10 avatar Mar 13 '23 11:03 joaovsc10

Hi @joaovsc10,

The branch at this point is way too old and needs to be redone.

Also, as I mention in the original message, the API is not ... great. I would argue that the API should mostly be copied from some other JS ecosystem library if possible.

But these are quite a lot of changes and both me and @javaducky have other, arguably more important in general, work that will have effects for more users. And there has been fairly little interest, given the lack of reported (or upvoted reports) of the obvious problems.

Having said that, we will try to review and possibly merge any PRs that try to make this extension more stable and usable. Just likely not work on it directly for at least some more time, and I can't guarantee we will ever come back to it on its own.

mstoykov avatar Mar 13 '23 13:03 mstoykov