Commit 6b8138f9 authored by Dan Melnic's avatar Dan Melnic Committed by Facebook Github Bot

Change kDefaultZeroCopyThreshold to 0 to avoid a regression and avoid a...

Change kDefaultZeroCopyThreshold to 0 to avoid a regression and avoid a failure while running as not root

Summary:
Change kDefaultZeroCopyThreshold to 0 to avoid a regression when using a buffer chain that exceeds 32K but each buffer is small.
Change the benchmark to set it's own threshold. Also use calloc vs malloc (in the benchmark only) to get around some weird kernel interaction on non zero copy enabled systems - 2 back to back tests report very different results.

Reviewed By: djwatson

Differential Revision: D6112299

fbshipit-source-id: 3895d3ece2925c4626284ff364495708293edc3e
parent 30c1e1dc
...@@ -504,7 +504,7 @@ class AsyncSocket : virtual public AsyncTransportWrapper { ...@@ -504,7 +504,7 @@ class AsyncSocket : virtual public AsyncTransportWrapper {
void setReadCB(ReadCallback* callback) override; void setReadCB(ReadCallback* callback) override;
ReadCallback* getReadCallback() const override; ReadCallback* getReadCallback() const override;
static const size_t kDefaultZeroCopyThreshold = 32768; // 32KB static const size_t kDefaultZeroCopyThreshold = 0;
bool setZeroCopy(bool enable); bool setZeroCopy(bool enable);
bool getZeroCopy() const { bool getZeroCopy() const {
......
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
using namespace folly; using namespace folly;
static constexpr auto const kZeroCopyThreshold = 4096;
class TestAsyncSocket { class TestAsyncSocket {
public: public:
explicit TestAsyncSocket( explicit TestAsyncSocket(
...@@ -77,6 +79,9 @@ class TestAsyncSocket { ...@@ -77,6 +79,9 @@ class TestAsyncSocket {
zeroCopy_ = enable; zeroCopy_ = enable;
if (sock_) { if (sock_) {
sock_->setZeroCopy(zeroCopy_); sock_->setZeroCopy(zeroCopy_);
if (zeroCopy_) {
sock_->setZeroCopyWriteChainThreshold(kZeroCopyThreshold);
}
} }
} }
...@@ -162,8 +167,12 @@ class TestAsyncSocket { ...@@ -162,8 +167,12 @@ class TestAsyncSocket {
} }
bool writeBuffer() { bool writeBuffer() {
// use calloc to make sure the memory is touched
// if the memory is just malloc'd, running the zeroCopyOn
// and the zeroCopyOff back to back on a system that does not support
// zerocopy leads to the second test being much slower
writeBuffer_ = writeBuffer_ =
folly::IOBuf::takeOwnership(::malloc(bufferSize_), bufferSize_); folly::IOBuf::takeOwnership(::calloc(1, bufferSize_), bufferSize_);
if (sock_ && writeBuffer_) { if (sock_ && writeBuffer_) {
sock_->writeChain( sock_->writeChain(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment