Closed FrothyB closed 9 months ago
Running strace
indicates that both cases use a sendto
syscall, but ssl::stream
results in an extra allocation with mmap
.
Turns out that OpenSSL has a large call-stack, and a significant amount of branching and pointer indirection. Using it very frequently or in a loop the performance hit is as expected, but if you use it less often then performance is very poor as caches and branch predictors are not warmed up to handle it.
net::write(socket_, net::buffer(data, length), ec);
takes about 8 microseconds for atcp::socket
and about 16 for assl::stream<tcp::socket>
. The data is small (<100 bytes). This seems like a larger performance delta than should be expected, could there be some inefficiency in the implementation of ssl::stream causing this? How can I help narrow it down?Note that for a simple
tcp::socket
,net::write
andsocket_.write_some
take roughly the same amount of time, withwrite_some
being marginally faster.