fanhualta commented on a change in pull request #2322:
URL: https://github.com/apache/iotdb/pull/2322#discussion_r550389888



##########
File path: 
service-rpc/src/main/java/org/apache/iotdb/rpc/TCompressedElasticFramedTransport.java
##########
@@ -64,14 +69,30 @@ protected void readFrame() throws TTransportException {
     }
   }
 
-  private TByteBuffer resizeCompressBuf(int size, TByteBuffer byteBuffer) {
-    double expandFactor = 1.5;
-    double loadFactor = 0.6;
-    if (byteBuffer.getByteBuffer().capacity() < size) {
-      int newCap = (int) Math.min(size * expandFactor, maxLength);
-      byteBuffer = new TByteBuffer(ByteBuffer.allocate(newCap));
-    } else if (byteBuffer.getByteBuffer().capacity() * loadFactor > size) {
-      byteBuffer = new TByteBuffer(ByteBuffer.allocate(size));
+  private TByteBuffer resizeCompressBuf(int size, TByteBuffer byteBuffer)
+      throws TTransportException {
+    if (size > RpcUtils.FRAME_HARD_MAX_LENGTH) {
+      close();
+      throw new TTransportException(TTransportException.CORRUPTED_DATA,
+          "Frame size (" + size + ") larger than protect max length (" + 
RpcUtils.FRAME_HARD_MAX_LENGTH
+              + ")!");
+    }
+
+    final int currentCapacity = byteBuffer.getByteBuffer().capacity();
+    final double loadFactor = 0.6;
+    if (currentCapacity < size) {
+      // Increase by a factor of 1.5x
+      int growCapacity = currentCapacity + (currentCapacity >> 1);
+      int newCapacity = Math.max(growCapacity, size);
+      byteBuffer = new TByteBuffer(ByteBuffer.allocate(newCapacity));
+      bufTooLargeCounter = MAX_BUFFER_OVERSIZE_TIME;
+    } else if (currentCapacity > softMaxLength && currentCapacity * loadFactor 
> size
+        && bufTooLargeCounter-- <= 0
+        && System.currentTimeMillis() - lastShrinkTime > MIN_SHRINK_INTERVAL) {
+      // do not shrink beneath the initial size and do not shrink too often
+      byteBuffer = new TByteBuffer(ByteBuffer.allocate(size + (currentCapacity 
- size) / 2));
+      lastShrinkTime = System.currentTimeMillis();

Review comment:
       Is it necessary to consider the concurrency performance of this method 
`System.currentTimeMillis()` ? 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to