mirror of
https://github.com/apple/swift-nio-ssl
synced 2026-11-25 04:47:52 +00:00
Motivation: ByteBufferBIOs will grow their outbound buffer until flush is called. They will retain their capacity at however large it got to avoid reallocating, as they assume that your write pattern will be fairly consistent. In some cases this is a bad strategy, because it overcommits data. To allow users to reclaim this data, we can add a configuration option that will shrink the playload on the next write. Modifications: - Added support for ByteBufferBIO to shrink the payload. - Plumbed up support for handler configuration. - Tests that shrinkage actually works. Result: Users can reclaim memory.
39 lines
1.8 KiB
Swift
39 lines
1.8 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the SwiftNIO open source project
|
|
//
|
|
// Copyright (c) 2023 Apple Inc. and the SwiftNIO project authors
|
|
// Licensed under Apache License v2.0
|
|
//
|
|
// See LICENSE.txt for license information
|
|
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
extension NIOSSLHandler {
|
|
/// Configuration for a specific instance of ``NIOSSLHandler``, either client or server.
|
|
///
|
|
/// This type is distinct from ``TLSConfiguration`` because it does not contain settings that
|
|
/// apply to TLS itself. Instead, this configuration manages how the ``NIOSSLHandler`` itself
|
|
/// operates.
|
|
public struct Configuration: Hashable, Sendable {
|
|
/// The maximum number of bytes we'll preserve in the outbound buffer that ``NIOSSLHandler``
|
|
/// holds.
|
|
///
|
|
/// This buffer is not typically deallocated, as it is re-used throughout the lifetime of
|
|
/// the program. In cases where there are extremely large peak writes that are outliers in
|
|
/// the code, the buffer may remain excessively large.
|
|
///
|
|
/// Set this value to a lower value to avoid preserving too much memory. This will cause
|
|
/// ``NIOSSLHandler`` to reallocate memory more often, which can inhibit performance, so
|
|
/// avoid lowering this value unless you're running into trouble with memory pressure and
|
|
/// are confident that ``NIOSSLHandler`` is at fault.
|
|
public var maximumPreservedOutboundBufferCapacity: Int
|
|
|
|
public init() {
|
|
self.maximumPreservedOutboundBufferCapacity = .max
|
|
}
|
|
}
|
|
}
|