keepalive.go 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. *
  3. * Copyright 2017 gRPC authors.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. // Package keepalive defines configurable parameters for point-to-point healthcheck.
  19. package keepalive
  20. import (
  21. "time"
  22. )
  23. // ClientParameters is used to set keepalive parameters on the client-side.
  24. // These configure how the client will actively probe to notice when a connection is broken
  25. // and send pings so intermediaries will be aware of the liveness of the connection.
  26. // Make sure these parameters are set in coordination with the keepalive policy on the server,
  27. // as incompatible settings can result in closing of connection.
  28. type ClientParameters struct {
  29. // After a duration of this time if the client doesn't see any activity it pings the server to see if the transport is still alive.
  30. Time time.Duration // The current default value is infinity.
  31. // After having pinged for keepalive check, the client waits for a duration of Timeout and if no activity is seen even after that
  32. // the connection is closed.
  33. Timeout time.Duration // The current default value is 20 seconds.
  34. // If true, client runs keepalive checks even with no active RPCs.
  35. PermitWithoutStream bool // false by default.
  36. }
  37. // ServerParameters is used to set keepalive and max-age parameters on the server-side.
  38. type ServerParameters struct {
  39. // MaxConnectionIdle is a duration for the amount of time after which an idle connection would be closed by sending a GoAway.
  40. // Idleness duration is defined since the most recent time the number of outstanding RPCs became zero or the connection establishment.
  41. MaxConnectionIdle time.Duration // The current default value is infinity.
  42. // MaxConnectionAge is a duration for the maximum amount of time a connection may exist before it will be closed by sending a GoAway.
  43. // A random jitter of +/-10% will be added to MaxConnectionAge to spread out connection storms.
  44. MaxConnectionAge time.Duration // The current default value is infinity.
  45. // MaxConnectinoAgeGrace is an additive period after MaxConnectionAge after which the connection will be forcibly closed.
  46. MaxConnectionAgeGrace time.Duration // The current default value is infinity.
  47. // After a duration of this time if the server doesn't see any activity it pings the client to see if the transport is still alive.
  48. Time time.Duration // The current default value is 2 hours.
  49. // After having pinged for keepalive check, the server waits for a duration of Timeout and if no activity is seen even after that
  50. // the connection is closed.
  51. Timeout time.Duration // The current default value is 20 seconds.
  52. }
  53. // EnforcementPolicy is used to set keepalive enforcement policy on the server-side.
  54. // Server will close connection with a client that violates this policy.
  55. type EnforcementPolicy struct {
  56. // MinTime is the minimum amount of time a client should wait before sending a keepalive ping.
  57. MinTime time.Duration // The current default value is 5 minutes.
  58. // If true, server expects keepalive pings even when there are no active streams(RPCs).
  59. PermitWithoutStream bool // false by default.
  60. }