Change kDefaultZeroCopyThreshold to 0 to avoid a regression and avoid a failure while...
[folly.git] / folly / io / async / test / ZeroCopyBenchmark.cpp
index 7f397e00a0eaf9ea2a937e64dab8639b74be522d..6ef917ea9848068fee5ac55e14adae2706fce864 100644 (file)
@@ -27,6 +27,8 @@
 
 using namespace folly;
 
+static constexpr auto const kZeroCopyThreshold = 4096;
+
 class TestAsyncSocket {
  public:
   explicit TestAsyncSocket(
@@ -77,6 +79,9 @@ class TestAsyncSocket {
     zeroCopy_ = enable;
     if (sock_) {
       sock_->setZeroCopy(zeroCopy_);
+      if (zeroCopy_) {
+        sock_->setZeroCopyWriteChainThreshold(kZeroCopyThreshold);
+      }
     }
   }
 
@@ -162,8 +167,12 @@ class TestAsyncSocket {
   }
 
   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_ =
-        folly::IOBuf::takeOwnership(::malloc(bufferSize_), bufferSize_);
+        folly::IOBuf::takeOwnership(::calloc(1, bufferSize_), bufferSize_);
 
     if (sock_ && writeBuffer_) {
       sock_->writeChain(