mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-26 17:38:45 +01:00
Decrease CPU usage caused by tls:send with large data.
Sending one large chunk of data with tls:send eats lots of CPU power and blocks whole Erlang emulator. This is caused by the fact that encrypted output is read from memory BIO in 1k chunks. Memory BIO, after reading data, shifts the remaining part. If large chunks of data (few MB) is sent and then read in 1k chunks, then a _lot_ of shifting is performed eating CPU. The solution is to simply allocate binary of the needed size (amount of data in memory BIO can be retrieved with BIO_ctrl_pending) and then issue only one read that reads the whole data.
This commit is contained in:
parent
32ff6b56eb
commit
c4f9a050c9
@ -407,22 +407,12 @@ static int tls_drv_control(ErlDrvData handle,
|
|||||||
break;
|
break;
|
||||||
case GET_ENCRYPTED_OUTPUT:
|
case GET_ENCRYPTED_OUTPUT:
|
||||||
die_unless(d->ssl, "SSL not initialized");
|
die_unless(d->ssl, "SSL not initialized");
|
||||||
size = BUF_SIZE + 1;
|
size = BIO_ctrl_pending(d->bio_write) + 1;
|
||||||
rlen = 1;
|
|
||||||
b = driver_alloc_binary(size);
|
b = driver_alloc_binary(size);
|
||||||
b->orig_bytes[0] = 0;
|
b->orig_bytes[0] = 0;
|
||||||
while ((res = BIO_read(d->bio_write,
|
BIO_read(d->bio_write, b->orig_bytes + 1, size - 1);
|
||||||
b->orig_bytes + rlen, BUF_SIZE)) > 0)
|
|
||||||
{
|
|
||||||
//printf("%d bytes of encrypted data read from state machine\r\n", res);
|
|
||||||
|
|
||||||
rlen += res;
|
|
||||||
size += BUF_SIZE;
|
|
||||||
b = driver_realloc_binary(b, size);
|
|
||||||
}
|
|
||||||
b = driver_realloc_binary(b, rlen);
|
|
||||||
*rbuf = (char *)b;
|
*rbuf = (char *)b;
|
||||||
return rlen;
|
return size;
|
||||||
case GET_DECRYPTED_INPUT:
|
case GET_DECRYPTED_INPUT:
|
||||||
if (!SSL_is_init_finished(d->ssl))
|
if (!SSL_is_init_finished(d->ssl))
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user