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

re-use existing connection on getData endpoint #130

Merged
merged 2 commits into from
Dec 26, 2024

Conversation

rmlamarche
Copy link

Currently, the getData endpoint establishes a new socket for every individual variable description + type. This results in a lot of TCP handshakes (and DNS queries if using a domain name for the NUT server -- see #126 ). When running PeaNUT in kubernetes, I was frequently experiencing "500 internal server error" messages in the client (as well as in the data API endpoints + InfluxDB writer failing). I never really found a "smoking gun" but maybe something about the flood of connections didn't play nicely with my CNI. I have been able to successfully run PeaNUT + InfluxDB in kubernetes with my changes and it has been running smoothly, it hasn't missed a beat

I re-worked the getData endpoint to establish a single connection and re-use it for each command it executes. Because of this re-work, I also needed to be more careful about cleaning up event listeners on the socket so as not to create a memory leak, so there are a few minor changes there as well.

This is my first time attempting to contribute to PeaNUT, I tried my best to follow the coding style, but happy to make any changes or implement this in a different way if needed. Really like the project, but have been having these connection issues with the 4.x releases when running in kubernetes, so I'm hoping something like this can be implemented!

@Brandawg93
Copy link
Owner

Thanks for the PR! I actually had it similar to your previous implementation before, but kept getting annoyed with the MaxEventListeners errors so I changed. Your PR inspired me to go back and rethink it. 😄 I made some minor changes to your PR, but the bulk of it is the same. Let me know if this still works for you, and I'll merge it.

@rmlamarche
Copy link
Author

Built & running in my cluster with your changes -- seems to still be working! Running with 10s InfluxDB interval & 1s auto refresh in the PeaNUT client and not seeing any issues with event listener leaks.

If you're happy with the changes I'm okay with it merging. Happy Holidays!

@Brandawg93
Copy link
Owner

Awesome! I'll put this in the next release. Happy Holidays!

@Brandawg93 Brandawg93 merged commit 378cfaf into Brandawg93:main Dec 26, 2024
1 check passed
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

Successfully merging this pull request may close these issues.

2 participants