How to test a NodeJS UDP server with Artillery?

97 views Asked by At

I have a basic dgram UDP server in NodeJS and I want to apply a load test to this server, using Artillery. However, I couldn't find a way to achieve this.

Artillery has engines such as HTTP, WebSocket, SocketIO and PlayWright. As I know, SocketIO and WebSocket TCP protocols. So, how do I do a UDP test with these engines?

One of those engines or another implementation of UDP protocol in NodeJS are welcomed in my case. Is there a way to achieve this?

My UDP server:

const UDP = require('dgram')
const server = UDP.createSocket('udp4')
const port = 2222

server.on('listening', () => {
  // Server address it’s using to listen

  const address = server.address()

  console.log('Listining to ', 'Address: ', address.address, 'Port: ', address.port)
})

server.on('message', (message, info) => {
  console.log('Message', message.toString())

  const response = Buffer.from('Message Received')

  //sending back response to client

  server.send(response, info.port, info.address, (err) => {
    if (err) {
      console.error('Failed to send response !!')
    } else {
      console.log('Response send Successfully')
    }
  })
})

server.bind(port)

My Artillery config file:

config:
  target: http://localhost:2222
  phases:
    - duration: 30
      arrivalRate: 10 
      name: Warm up the API
    - duration: 30
      arrivalRate: 10
      rampTo: 15
      name: Ramp up to peak load

scenarios:
  - name: WebSocket Test
    engine: "socketio" # Enable the Socket.io engine
    flow:
      - emit:
          channel: "message"
          data: "Hello World"
1

There are 1 answers

0
bernardobridge On

I answered this question on Artillery's Github Discussions: https://github.com/artilleryio/artillery/discussions/2189. Quoting from my answer there:

The socketio engine which you're trying to use uses SocketIO's own communication protocol which is built on top of TCP, not UDP, AFAIK. So I don't think you'd be able to test UDP with it.

However, Artillery is pretty extensible precisely for this reason and you can build your own engine to test anything with it. We have a blog post detailing how to do this yourself - https://www.artillery.io/blog/extend-artillery-by-creating-your-own-engines, as well as an example.

Additionally, from a quick search on npm, you can see there's a few examples from the community, for instance: