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

[FreeBSD] speed up net_connections() #2343

Merged
merged 7 commits into from Dec 20, 2023
Merged

[FreeBSD] speed up net_connections() #2343

merged 7 commits into from Dec 20, 2023

Conversation

giampaolo
Copy link
Owner

Summary

  • OS: FreeBSD
  • Bug fix: no
  • Type: core, performance

Description

Modify psutil.net_connections() to retrieving unnecessary connection types unless explicitly asked. E.g., on an IDLE system with few IPv6 connections this will run around 4 times faster:

import psutil, time
started = time.monotonic()
for x in range(1000):
    psutil.net_connections("tcp6")
print(f"completed in {(time.monotonic() - started):.4f} secs")

Before all connection types (TCP, UDP, UNIX) were retrieved internally, even if only a portion was returned.

@giampaolo giampaolo changed the title [Freebsd] speed up net_connections() [FreeBSD] speed up net_connections() Dec 20, 2023
@giampaolo giampaolo merged commit 13e1fe7 into master Dec 20, 2023
20 of 23 checks passed
@giampaolo giampaolo deleted the freebsd-filter-cons branch December 20, 2023 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant