Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to determine/debug if connections are being reused? #95

Open
Ghazgkull opened this issue Jan 26, 2021 · 1 comment
Open

How to determine/debug if connections are being reused? #95

Ghazgkull opened this issue Jan 26, 2021 · 1 comment

Comments

@Ghazgkull
Copy link

I'm attempting to enable connection reuse for a simple application using this module, but I'm not sure how to verify whether connections are being reused.

I tried adding some simple logging after each request to look at the agent status. Is that the right way to determine if it's working?

Using the default options, I tried making three requests using an HTTPS agent, and I see the following statuses printed using JSON.stringify(agent.getCurrentStatus()). Am I right to think that connections aren't being reused here? Is there any way to debug connection reuse?

Agent status: {"createSocketCount":1,"createSocketErrorCount":0,"closeSocketCount":0,"errorSocketCount":0,"timeoutSocketCount":0,"requestCount":1,"freeSockets":{"redacted.com:443::::::::::::::::::":1},"sockets":{},"requests":{}}
Agent status: {"createSocketCount":1,"createSocketErrorCount":0,"closeSocketCount":0,"errorSocketCount":0,"timeoutSocketCount":0,"requestCount":1,"freeSockets":{"redacted.com:443::::::::::::::::::":1},"sockets":{},"requests":{}}
Agent status: {"createSocketCount":1,"createSocketErrorCount":0,"closeSocketCount":0,"errorSocketCount":0,"timeoutSocketCount":0,"requestCount":1,"freeSockets":{"redacted.com:443::::::::::::::::::":1},"sockets":{},"requests":{}}```
@Ghazgkull
Copy link
Author

After further exploration, I think the problem was that I was only using the agent to make serial requests. By swapping my agent scope to reuse the same agent for a large number of parallel requests, the status data started to really make sense and clearly showed connection reuse.

For example:

  agent status: {"createSocketCount":2007,"createSocketErrorCount":0,"closeSocketCount":1382,"errorSocketCount":1,"timeoutSocketCount":1,"requestCount":92467,"freeSockets":{"redacted.com:443::::::::::::::::::":107},"sockets":{"redacted.com:443::::::::::::::::::":518},"requests":{}}```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant