TsgcWebSocketHTTPServer › 事件 › OnHTTP2BeforeAsyncRequest
在 HTTP/2 请求入队之前触发,以便应用程序选择在线程池还是连接线程中运行该请求。
property OnHTTP2BeforeAsyncRequest: TsgcWSOnBeforeHttp2AsyncRequest;
// TsgcWSOnBeforeHttp2AsyncRequest = procedure(Sender: TObject; Connection: TsgcWSConnection; const ARequestInfo: TIdHTTPRequestInfo; var Async: Boolean) of object
—
当 HTTP2Options.PoolOfThreads.Enabled 为 True 时,服务器在工作线程池(HTTP2Options.Threads)上调度传入的 HTTP/2 请求,以利用 HTTP/2 多路复用。OnHTTP2BeforeAsyncRequest 在每个请求排队之前触发:检查 ARequestInfo.Document 以决定,并将 Async 设置为 True(默认值)以在线程池中运行,或设置为 False 以在连接线程中运行。将短请求路由到连接线程可避免线程池开销,同时保持慢速请求的线程化,这是推荐的微调策略。
procedure OnHTTP2BeforeAsyncRequest(Sender: TObject; Connection: TsgcWSConnection;
const ARequestInfo: TIdHTTPRequestInfo; var Async: Boolean);
begin
if ARequestInfo.Document = '/fast-request' then
Async := False;
end;