1

I created a simple server client using Asio (non-Boost), and am using it for a simple test of data transfer speed.

Server:

  • Create buffer (4 MB)
  • When a client connects (callback from async_accept)
    1. Start timer
    2. Send buffer to client (async_write)
    3. Wait for response from client (callback from async_read)
    4. Repeat step 2-3 100 times
    5. Stop timer
    6. Calculate transfer speed (100 * buffer size * 8 / time)

Client

  • Connect to server
    1. Wait for data from server (callback from async_read)
    2. Send a single byte back to server (async_write)
    3. Repeat

I have implemented this both with and without SSL/TLS encryption. The non-secure version achieves speeds at around 15.0 Gbps through localhost, but the encrypted version slows way down to about 0.3 Gbps.

Is this expected? If not, any ideas what could be causing this?

2 Answers 2

1

The task has become CPU bound. You can easily verify that using a task manager.

Also compare with netcat vs openssl s_server/s_client to see the same effects. E.g. for data.bin being 32MiB of random data, I get:

$ for a in {1..100}; do cat data.bin; done | pv | openssl enc -e -kfile server.pem -pass test -out data.bin.crypt
3,12GiB 0:00:08 [ 392MiB/s]

That's just time required for the server side to encrypt the data.

3
  • So does this mean there is no way to transfer at 1 Gbps speeds when needing to encrypt data because the CPU takes too long to process the data before sending it? Commented Jul 14, 2018 at 4:31
  • All I can say is that when using openssl s_server this appears to be the case. There could be a QoI issue in those tools. But the timings I got from them correspond to the timings I got from my own tester in Asio (with SSL vs witthout SSL)
    – sehe
    Commented Jul 18, 2018 at 12:53
  • I can't find the version of the code I used with SSL enabled, but it is a minor edit from this: without SSL
    – sehe
    Commented Jul 18, 2018 at 12:56
1

Is this expected?

No. TLS is not less than 1/3 the speed of plaintext over a sufficiently long transfer. I tested this extensively ten or more years ago, and computers have got a lot faster since then.

If not, any ideas what could be causing this?

You are probably using inadequate buffering between your application and the TLS layer. For example, if you send one byte at a time to TLS here can be a data explosion of 45 times.

2
  • I am sending 4 MB at a time as follows: uint32_t size = 4 * 1024 *1024; uint8_t *buffer = new uint8_t[size]; asio::async_write(socket, asio::buffer(buffer, size), complete_callback); Commented Jul 14, 2018 at 4:25
  • @EJP can you support it with a benchmark that we can repeat? I did when writing my answer.
    – sehe
    Commented Jul 18, 2018 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.