# Load testing a protocol buffers based server application

**URL:** <https://community.gatling.io/t/load-testing-a-protocol-buffers-based-server-application/1372>\
**Category:** Gatling (Open-Source)\
**Created:** [September 6, 2014, 8:12pm UTC](https://community.gatling.io/t/load-testing-a-protocol-buffers-based-server-application/1372 "2014-09-06T20:12:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ingo\_Jaeckel](https://avatars.discourse-cdn.com/v4/letter/i/c37758/32.png) [@Ingo\_Jaeckel](https://community.gatling.io/u/Ingo_Jaeckel)\
**Post date:** [September 6, 2014, 8:12pm UTC](https://community.gatling.io/t/load-testing-a-protocol-buffers-based-server-application/1372/1 "2014-09-06T20:12:42Z")

</div>

Hi,

I want to loadtest a server application that uses Google protocol buffers. Of course all the .proto files (RPC calls, request/response objects) are compiled into .java files that are bundled up into a .JAR. I would like to add this JAR file as a dependency to my Gatling loadtest. I want that Gatling invokes those protobuf RPCs just as any other loadtest.

However, I am unsure if/how this would work with Gatling’s current DSL. My request/response bodies are all binary. And ideally I can hide this as much as possible from the load test. I am looking for a way to use the generated protobuf Java code as much as possible for deserializing and sending requests. But I would like to use Gatling’s DSL to specify which RPCs to call.

How would I add my JAR file as a dependency to the Gatling loadtest?  
Assuming my generated code is on Gatling’s classpath, how would I use Gatling’s DSL to test my protobuf-based server?

Thanks,  
Ingo

---

<div class="post-metadata">

**Author:** ![Ingo\_Jaeckel](https://avatars.discourse-cdn.com/v4/letter/i/c37758/32.png) [@Ingo\_Jaeckel](https://community.gatling.io/u/Ingo_Jaeckel)\
**Post date:** [September 10, 2014, 6:59pm UTC](https://community.gatling.io/t/load-testing-a-protocol-buffers-based-server-application/1372/2 "2014-09-10T18:59:07Z")

</div>

In other words: Can I loadtest a protobuf-based server with Gatling already, or would I have to customize Gatling to do that?

Thanks,  
Ingo

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [September 11, 2014, 8:16am UTC](https://community.gatling.io/t/load-testing-a-protocol-buffers-based-server-application/1372/3 "2014-09-11T08:16:16Z")

</div>

Customize.

As protobuf requires you to ship and use the generated serializers, so that’s not something we can have built-in.

Regarding request bodies: you can probably use ByteArrayBody and feed it an Expression[Array[Byte]] that would perform your protobuf serialization.  
Regarding response bodies: you can probably use the bodyBytes check, with a transform step that would perform your protobuf deserialization.

Cheers,

Stéphane

---

<div class="post-metadata">

**Author:** ![Ingo\_Jaeckel](https://avatars.discourse-cdn.com/v4/letter/i/c37758/32.png) [@Ingo\_Jaeckel](https://community.gatling.io/u/Ingo_Jaeckel)\
**Post date:** [December 11, 2014, 9:30pm UTC](https://community.gatling.io/t/load-testing-a-protocol-buffers-based-server-application/1372/4 "2014-12-11T21:30:45Z")

</div>

Hey Stéphane,

Do you mind providing some example Scala code to demonstrate the approach? I have found a [code snippet on stackoverflow](http://stackoverflow.com/questions/23371161/gatling2-get-response-body-as-byte-array) that contains the ByteArrayBody type you mentioned:

`

```auto
val request = exec(http("FirstRequest")
    .post("/message")
    .body(new ByteArrayBody((session: Session) => getFirstRequest(session)))
    // ...

val response = exec(http("SecondRequest")
    .post("/message")
    .body(new ByteArrayBody((session: Session) => getSecondRequest(session)))
    // ...

```

`

Would I directly pass a bytes array into ByteArrayBody?

I don’t quite understand the syntax of the value passed into the ByteArrayBody constructor. Can you elaborate what this actually does?

`

```auto
(session: Session) => getSecondRequest(session)

```

`

Just for the record: This was requested and rejected in this Github issue: [https://github.com/gatling/gatling/issues/96](https://github.com/gatling/gatling/issues/96).

Thanks,  
Ingo

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [December 11, 2014, 10:30pm UTC](https://community.gatling.io/t/load-testing-a-protocol-buffers-based-server-application/1372/5 "2014-12-11T22:30:58Z")

</div>

Things are pretty clear in the SOF thread 🙂

getFirstRequest and getSecondRequest are methods that take a Session and return an Array[Byte] (or better, a Validation[Array[Byte]).

In those, you would populate some POJO with values coming from the Session, and serialize it.

For example:

getFirstRequest(session: Session) =

for {  
id ← session(“id”).validate[Int]  
name ← session(“id”).validate[String]  
email ← session(“id”).validate[String]  
} yield Person.newBuilder.setId(id).set(name).set(email).toByteArray
