k6 icon indicating copy to clipboard operation
k6 copied to clipboard

Support for websocket with protobuf binary

Open 4nif opened this issue 3 years ago • 3 comments

From k6 blog https://k6.io/blog/performance-testing-grpc-services, we can use grpc with protobuf binary message in the latest version

Is it possible to have native support for websocket with protobuf binary message?

According to https://k6.io/docs/javascript-api/k6-ws/socket/socket-send-data, only support json/string

4nif avatar Jan 14 '21 13:01 4nif

There is technically no problem. but is currently not supported.

The current k6 WebSocket implementation does not support sending non-text messages at all. The fix for that isn't hard and was actually done by user over a year ago at this time, and we hoped they will make a PR, but that did not happen so :shrug: .

But since then goja (the JS VM k6 uses) started actually supporting ArrayBuffer, so ... now probably that code won't look exactly like that but will be able to work with both []byte and ArrayBuffer, if we decide to include it. Some work with supporting ArrayBuffer through k6 is underway.

If that is done we just need a way to protobuf encode to ArrayBuffer, which likely will go in the encoding module (or submodule of it).

Obviously, we also can just have 'SendProtobufMessage' be a WebSocket method, but it seems to me we will need protobuf encoding in other places, so I don't think it's such a good idea :thinking:.

Either way, this is unlikely, due to priorities, to be picked up by the k6 team for at least one more release cycle, probably more :(. If anyone would like to give it a go, please express that desire and the k6 team will try to come to an agreement on at least what the change to support this will need to look like :).

As an alternative, I guess someone can use xk6 to make all the changes required to get this to work as an extension to k6. This might be as simple as just copying the ws module and adding the SendProtobufMessage above or having both adding the SendBinary one and having another extension that is the protobuf encoding. I would even recommend that this is the way it starts so whoever makes it has an easier time sharing it ;)

mstoykov avatar Jan 14 '21 15:01 mstoykov

As an alternative, I guess someone can use xk6 to make all the changes required to get this to work as an extension to k6. This might be as simple as just copying the ws module and adding the SendProtobufMessage above or having both adding the SendBinary one and having another extension that is the protobuf encoding. I would even recommend that this is the way it starts so whoever makes it has an easier time sharing it ;)

Is there some sample code for xk6 support protobuf binary?

oslook avatar Jun 28 '22 07:06 oslook

Is there some sample code for xk6 support protobuf binary?

Don't think so, sorry.

For the record https://github.com/grafana/k6/pull/1841/ added sendBinary which can now send ArrayBuffers over websockets. So you just need the protobuf marshalling.

A quick search send me to https://community.k6.io/t/using-protobuf-with-k6/47 which links to https://github.com/sparrowjack/k6_protobuff_demo/tree/master which likely needs to be update, but it will probably work :crossed_fingers:

I would recommend trying it out first and if the performance or compatibility isn't okay for you to then try to play with xk6.

mstoykov avatar Jun 28 '22 08:06 mstoykov

Hi there,

After more than a year and a half with no activity, the low amount of traction (close to zero) this issue received, and considering that priorities haven't changed (this one still extremely low), I proceed to close this issue for now.

However, it is worth mentioning that, despite of closing it for now, if anyone willing to see this feature in k6, and with capacity to contribute, we might consider supporting and reviewing a community contribution to get so.

Thanks!

joanlopez avatar Apr 08 '24 07:04 joanlopez