Node.js의 Agent.maxSockets 속성

王林
풀어 주다: 2023-08-24 12:29:09
앞으로
1289명이 탐색했습니다.

Node.js 中的 agent.maxSockets 属性

agent.maxSockets 속성은 에이전트가 각 소스에 대해 동시에 열 수 있는 소켓 수를 정의합니다. 기본적으로 이 값은 무한대로 설정됩니다. 이것은 또한 "http" 모듈의 일부입니다.

Syntax

agent.maxSockets: number
로그인 후 복사

Parameters

위 함수는 다음 매개변수를 허용할 수 있습니다. -

  • number – 이는 에이전트가 가질 수 있는 동시 소켓 수를 정의합니다. 기본값은 Infinity로 설정되어 있습니다.

Example

maxSockets.js라는 파일을 만들고 다음 코드 조각을 복사하세요. 파일을 생성한 후 아래 예에 표시된 대로 다음 명령을 사용하여 이 코드를 실행합니다.

node maxSockets.js
로그인 후 복사

maxSockets.js

// agent.maxSockets method Demo example

// Importing the http & agentkeepalive module
const http = require('http');
const agent = require('agentkeepalive');

const keepaliveAgent = new agent({
   maxSockets: 100,
   maxFreeSockets: 10,
   timeout: 60000, // active socket keepalive for 60 seconds
   freeSocketTimeout: 30000, // free socket keepalive for 30 seconds
});

const options = {
   host: 'tutorialspoint.com',
   port: 80,
   path: '/',
   method: 'GET',
   agent: keepaliveAgent,
};
console.log("Max free sockets: ",keepaliveAgent.maxSockets);
console.log('[%s] agent status changed: %j', Date(),
keepaliveAgent.getCurrentStatus());
로그인 후 복사

output

C:\homeode>> node maxSockets.js
Max sockets: 100
[Fri Apr 30 2021 12:28:24 GMT+0530 (India Standard Time)] agent status
changed:
{"createSocketCount":0,"createSocketErrorCount":0,"closeSocketCount":0,"errorS
ocketCount":0,"timeoutSocketCount":0,"requestCount":0,"freeSockets":{},"socket
s":{},"requests":{}}
로그인 후 복사

위 내용은 Node.js의 Agent.maxSockets 속성의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

원천:tutorialspoint.com
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!