İçeriğe geç

HTTP İstemci Ömrü (ARCH6083)

Anahtar ruby.performance.http-client-lifetime · Önem warning · Kategori performance

Her çağrıda yeni bir HTTP istemcisi/bağlantısı oluşturmak bağlantıyı yeniden kullanmaz ve soket tükenmesine yol açar. İstemciyi paylaşılan kalıcı bir örnek olarak tutun.

def fetch(path)
client = Net::HTTP.new("api.example.com", 443)
client.use_ssl = true
client.get(path).body
end
CLIENT = Net::HTTP.start("api.example.com", 443, use_ssl: true)
def fetch(path)
CLIENT.get(path).body
end

HTTP istemcisini bir kez oluşturup paylaşılan/havuzlanmış bir örnek olarak yeniden kullanın.