http2.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #pragma once
  2. #include "factory.h"
  3. #include "http_common.h"
  4. #include <util/datetime/base.h>
  5. #include <library/cpp/dns/cache.h>
  6. #include <utility>
  7. namespace NNeh {
  8. IProtocol* Http1Protocol();
  9. IProtocol* Post1Protocol();
  10. IProtocol* Full1Protocol();
  11. IProtocol* Http2Protocol();
  12. IProtocol* Post2Protocol();
  13. IProtocol* Full2Protocol();
  14. IProtocol* UnixSocketGetProtocol();
  15. IProtocol* UnixSocketPostProtocol();
  16. IProtocol* UnixSocketFullProtocol();
  17. //global options
  18. struct THttp2Options {
  19. //connect timeout
  20. static TDuration ConnectTimeout;
  21. //input and output timeouts
  22. static TDuration InputDeadline;
  23. static TDuration OutputDeadline;
  24. //when detected slow connection, will be runned concurrent parallel connection
  25. //not used, if SymptomSlowConnect > ConnectTimeout
  26. static TDuration SymptomSlowConnect;
  27. //input buffer size
  28. static size_t InputBufferSize;
  29. //http client input buffer politic
  30. static bool KeepInputBufferForCachedConnections;
  31. //asio threads
  32. static size_t AsioThreads;
  33. //asio server threads, - if == 0, use acceptor thread for read/parse incoming requests
  34. //esle use one thread for accepting + AsioServerThreads for process established tcp connections
  35. static size_t AsioServerThreads;
  36. //use ACK for ensure completely sending request (call ioctl() for checking emptiness output buffer)
  37. //reliable check, but can spend to much time (40ms or like it) (see Wikipedia: TCP delayed acknowledgment)
  38. //disabling this option reduce sending validation to established connection and written all request data to socket buffer
  39. static bool EnsureSendingCompleteByAck;
  40. //listen socket queue limit
  41. static int Backlog;
  42. //expecting receiving request data right after connect or inside receiving request data
  43. static TDuration ServerInputDeadline;
  44. //timelimit for sending response data
  45. static TDuration ServerOutputDeadline;
  46. //expecting receiving request for keep-alived socket
  47. //(Max - if not reached SoftLimit, Min, if reached Hard limit)
  48. static TDuration ServerInputDeadlineKeepAliveMax;
  49. static TDuration ServerInputDeadlineKeepAliveMin;
  50. //try write data into socket fd in contex handler->SendReply() call
  51. //(instead moving write job to asio thread)
  52. //this reduce sys_cpu load (less sys calls), but increase user_cpu and response time
  53. static bool ServerUseDirectWrite;
  54. //use http response body as error message
  55. static bool UseResponseAsErrorMessage;
  56. //pass all http response headers as error message
  57. static bool FullHeadersAsErrorMessage;
  58. //use details (SendError argument) as response body
  59. static bool ErrorDetailsAsResponseBody;
  60. //consider responses with 3xx code as successful
  61. static bool RedirectionNotError;
  62. //consider response with any code as successful
  63. static bool AnyResponseIsNotError;
  64. //enable tcp keepalive for outgoing requests sockets
  65. static bool TcpKeepAlive;
  66. //enable limit requests per keep alive connection
  67. static i32 LimitRequestsPerConnection;
  68. //enable TCP_QUICKACK
  69. static bool QuickAck;
  70. // enable write to socket via ScheduleOp
  71. static bool UseAsyncSendRequest;
  72. // Respect host name/address in THttpServer initialization (pass it it getaddrinfo)
  73. static bool RespectHostInHttpServerNetworkAddress;
  74. //set option, - return false, if option name not recognized
  75. static bool Set(TStringBuf name, TStringBuf value);
  76. };
  77. /// if exceed soft limit, reduce quantity unused connections in cache
  78. void SetHttp2OutputConnectionsLimits(size_t softLimit, size_t hardLimit);
  79. /// if exceed soft limit, reduce quantity unused connections in cache
  80. void SetHttp2InputConnectionsLimits(size_t softLimit, size_t hardLimit);
  81. /// for debug and monitoring purposes
  82. TAtomicBase GetHttpOutputConnectionCount();
  83. TAtomicBase GetHttpInputConnectionCount();
  84. std::pair<size_t, size_t> GetHttpOutputConnectionLimits();
  85. /// unused input sockets keepalive timeouts
  86. /// real(used) timeout:
  87. /// - max, if not reached soft limit
  88. /// - min, if reached hard limit
  89. /// - approx. linear changed[max..min], while conn. count in range [soft..hard]
  90. void SetHttp2InputConnectionsTimeouts(unsigned minSeconds, unsigned maxSeconds);
  91. }