| | |
| | | |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | static final ServerTCPNIOTransport SERVER_TRANSPORT = new ServerTCPNIOTransport(); |
| | | private static final long MB = 1024 * 1024; |
| | | |
| | | private ServerTCPNIOTransport() { |
| | | // Prevent instantiation. |
| | |
| | | // Enabled by default. |
| | | builder.setReuseAddress(Boolean.parseBoolean(reuseAddressStr)); |
| | | } |
| | | float heapPercent; |
| | | if (Runtime.getRuntime().maxMemory() < 1024 * MB) { |
| | | // Low heap |
| | | heapPercent = 0.01f; |
| | | } else { |
| | | // Compute a percentage to try to reach roughly 64Mb (big enough (tm)) |
| | | heapPercent = 64f * MB / Runtime.getRuntime().maxMemory(); |
| | | } |
| | | // Force usage of PooledMemoryManager which allows to use grizzly's buffers across threads. |
| | | builder.setMemoryManager(new PooledMemoryManager( |
| | | 1024, // Initial buffer size |
| | | 3, // Number of pools (with growing factor below this give us pools of 1K, 4K, 16k buffers) |
| | | 4, // Growing factor to apply on the size of the buffer polled by the next pool |
| | | selectorThreadCount, // Number of pool slices that every pool will stripe allocation requests across |
| | | heapPercent, // The percentage of the heap that this manager will use when populating the pools (5%) |
| | | 1f, // The percentage of buffers to be pre-allocated during MemoryManager initialization (100%) |
| | | true // true to use direct buffers or false to use heap buffers |
| | | )); |
| | | builder.setMemoryManager(new PooledMemoryManager(true)); |
| | | |
| | | final TCPNIOTransport transport = builder.build(); |
| | | |