grpc-swift icon indicating copy to clipboard operation
grpc-swift copied to clipboard

How can I set `maxReceiveMessageLength`, `maxSendMessageLength` and other `Channel.Argument` options (used in v0.x) in the swift-grpc v1.0.0-alpha.XX

Open smuravev opened this issue 4 years ago • 3 comments

Hi,

I would like to know how can I setup the following options (available in your lib v0.x) in the lib v1.0.0-alpha.XX, see Channel.Attributes:

  • maxReceiveMessageLength
  • maxSendMessageLength
  • maxConcurrentStreams
  • http2EnableTrueBinary
extension Channel {
  public enum Argument {

    /// Should we allow receipt of true-binary data on http2 connections?
    /// Defaults to on (true)
    public static func http2EnableTrueBinary(_ value: Bool) -> Channel.Argument { return .boolValued(key: "grpc.http2.true_binary", value: value) }
    
    /// Maximum number of concurrent incoming streams to allow on a http2 connection.
    public static func maxConcurrentStreams(_ value: UInt32) -> Channel.Argument { return .integerValued(key: "grpc.max_concurrent_streams", value: Int32(value)) }

    /// Maximum message length that the channel can receive (in byts).
    /// -1 means unlimited.
    public static func maxReceiveMessageLength(_ value: Int32) -> Channel.Argument { return .integerValued(key: "grpc.max_receive_message_length", value: value) }

    /// Maximum message length that the channel can send (in bytes).
    /// -1 means unlimited.
    public static func maxSendMessageLength(_ value: Int32) -> Channel.Argument { return .integerValued(key: "grpc.max_send_message_length", value: value) }
  }
}

Below, you can see example of my code - how I configure Channel using v1.0.0-alpha.XX - I also interested in the options described above. Unfortunately, I can't find similar options in the v1.0.0-alpha.XX. Can you please provide more info how to set these setting up ? Maybe couple of examples from you ? Or maybe your recommendations about alternative options (solution) available in v1.0.0-alpha.XX ?

    lazy var grpcFilesServiceClient = {
        Files_FilesServiceClient(channel: makeGrpcClientConnection(
            group: self.grpcGroup,
            useSSL: AppSettings.backendUseSSL,
            grpcClientLabel: Files_FilesServiceClient.typeName
        ))
    }()


    . . .


    private func makeGrpcClientConnection(group: EventLoopGroup, useSSL: Bool, grpcClientLabel: String) -> ClientConnection {
        let builder = useSSL
            ? ClientConnection.secure(group: group)
            : ClientConnection.insecure(group: group)
        
        // !!!!!!! Please, see here !!!!!!!
        //          UNFORTUNATELY, I can't find similar options (described above) in 
        //          the ClientConnection Builder in v1.0.0-alpha.XX
        builder
            .withBackgroundActivityLogger(self.logger)
            
            .withCallStartBehavior(.waitsForConnectivity)
            .withHTTPTargetWindowSize(65535)

            .withConnectionReestablishment(enabled: true)
            .withConnectionIdleTimeout(.minutes(1))
            .withConnectionTimeout(minimum: .seconds(10))
            .withConnectionBackoff(retries: .upTo(2))

            .withKeepalive(ClientConnectionKeepalive(
                interval: .seconds(20),
                timeout: .seconds(10),
                permitWithoutCalls: true,
                maximumPingsWithoutData: 2,
                minimumSentPingIntervalWithoutData: .minutes(1)
            ))
            
            .withErrorDelegate(GrpcClientConnectionErrorDelegate(grpcClientLabel))
            .withConnectivityStateDelegate(GrpcClientConnectivityStateDelegate(grpcClientLabel, logger: self.logger))
        
        return builder.connect(host: AppSettings.backendHost, port: AppSettings.backendPort)
    }

smuravev avatar Aug 14 '20 16:08 smuravev

I'm afraid none of these options are currently user configurable. It'd be great to support them but they're not high priority at the moment.


  • maxReceiveMessageLength
  • maxSendMessageLength

Neither of these are implemented in gRPC Swift, so there's a little bit of work to do here.

  • maxConcurrentStreams

Max concurrent streams is configurable in NIO HTTP/2, however, we don't currently expose this. We could, and doing so wouldn't be too difficult either. More broadly we can allow users to set the initial HTTP/2 settings via gRPC.

  • http2EnableTrueBinary

This is an interesting one: it's a custom HTTP/2 setting. NIO HTTP/2 doesn't support this at the moment so there's work to be done there and we'd also have to make it configurable via gRPC.

Are you interested in contributing any of this @smuravev?

glbrntt avatar Aug 17 '20 09:08 glbrntt

NIO HTTP/2 should allow users to configure custom HTTP/2 settings, so the true binary setting should be a grpc-only feature.

Lukasa avatar Aug 17 '20 09:08 Lukasa

looking for this changes:

maxReceiveMessageLength maxSendMessageLength maxConcurrentStreams http2EnableTrueBinary

kindly please update here

Amit011121 avatar Nov 02 '22 06:11 Amit011121