(boolean preferDirect)
| 164 | } |
| 165 | |
| 166 | private static ByteBufAllocator createByteBufAllocator(boolean preferDirect) { |
| 167 | int maxOrder; |
| 168 | logger.log(Level.FINE, "Creating allocator, preferDirect=" + preferDirect); |
| 169 | if (System.getProperty("io.netty.allocator.maxOrder") == null) { |
| 170 | // See the implementation of PooledByteBufAllocator. DEFAULT_MAX_ORDER in there is |
| 171 | // 11, which makes chunk size to be 8192 << 11 = 16 MiB. We want the chunk size to be |
| 172 | // 2MiB, thus reducing the maxOrder to 8. |
| 173 | maxOrder = 8; |
| 174 | logger.log(Level.FINE, "Forcing maxOrder=" + maxOrder); |
| 175 | } else { |
| 176 | maxOrder = PooledByteBufAllocator.defaultMaxOrder(); |
| 177 | logger.log(Level.FINE, "Using default maxOrder=" + maxOrder); |
| 178 | } |
| 179 | return new PooledByteBufAllocator( |
| 180 | preferDirect, |
| 181 | PooledByteBufAllocator.defaultNumHeapArena(), |
| 182 | // Assuming neither gRPC nor netty are using allocator.directBuffer() to request |
| 183 | // specifically for direct buffers, which is true as I just checked, setting arenas to 0 |
| 184 | // will make sure no direct buffer is ever created. |
| 185 | preferDirect ? PooledByteBufAllocator.defaultNumDirectArena() : 0, |
| 186 | PooledByteBufAllocator.defaultPageSize(), |
| 187 | maxOrder, |
| 188 | PooledByteBufAllocator.defaultSmallCacheSize(), |
| 189 | PooledByteBufAllocator.defaultNormalCacheSize(), |
| 190 | PooledByteBufAllocator.defaultUseCacheForAllThreads()); |
| 191 | } |
| 192 | |
| 193 | public static Metadata convertHeaders(Http2Headers http2Headers) { |
| 194 | if (http2Headers instanceof GrpcHttp2InboundHeaders) { |
no test coverage detected