httpx/sig/resolver/native.rbs
HoneyryderChuck 8bd4dc1fbd fix timers overhead causing spurious wakeups on the select loop
the change to read/write cancellation-driven timeouts as the default
timeout strategy revealed a performance regression; because these were
built on Timers, which never got unsubscribed, this meant that they were
kept beyond the duration of the request they were created for, and
needlessly got picked up for the next timeout tick.

This was fixed by adding a callback on timer intervals, which
unsubscribes them from the timer group when called; these would then be
activated after the timeout is not needed anymore (request send /
response received), thereby removing the overhead on subsequent
requests.

An additional intervals array is also kept in the connection itself;
timeouts from timers are signalled via socket wait calls, however they
were always resulting in timeouts, even when they shouldn't (ex: expect
timeout and send full response payload as a result), and with the wrong
exception class in some cases. By keeping intervals from its requests
around, and monitoring whether there are relevant request triggers, the
connection can therefore handle a timeout or bail out (so that timers
can fire the correct callback).
2023-10-24 22:53:22 +01:00

69 lines
1.6 KiB
Plaintext

module HTTPX
module Resolver
class Native < Resolver
extend Forwardable
include _ToIO
DEFAULTS: Hash[Symbol, untyped]
DNS_PORT: Integer
attr_reader family: ip_family
@options: Options
@ns_index: Integer
@nameserver: Array[String]
@socket_type: :udp | :tcp
@ndots: Integer
@start_timeout: Float?
@search: Array[String]
@_timeouts: Array[Numeric]
@timeouts: Hash[String, Array[Numeric]]
@connections: Array[Connection]
@read_buffer: String
@write_buffer: Buffer
@large_packet: Buffer?
@io: UDP | TCP
attr_reader state: Symbol
def call: () -> void
def interests: () -> (:r | :w | nil)
def <<: (Connection) -> void
def timeout: () -> Numeric?
def handle_socket_timeout: (Numeric interval) -> void
private
def initialize: (ip_family family, options options) -> void
def calculate_interests: () -> (:r | :w | nil)
def consume: () -> void
def do_retry: (?Numeric? loop_time) -> void
def dread: (Integer) -> void
| () -> void
def dwrite: () -> void
def parse: (String) -> void
def resolve: (?Connection connection, ?String hostname) -> void
def generate_candidates: (String) -> Array[String]
def build_socket: () -> (UDP | TCP)
def transition: (Symbol nextstate) -> void
def handle_error: (NativeResolveError | StandardError) -> void
def reset_hostname: (String hostname, ?connection: Connection, ?reset_candidates: bool) -> void
end
end
end