-
Notifications
You must be signed in to change notification settings - Fork 714
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
Optimize /proc traversal #450
Conversation
@inercia I don't know if it provides all you need but maybe you could use (or even extend) https://github.com/mitchellh/go-ps |
Actually, I don't think EDIT: maybe it has the same problems as procspy, feel free to disregard my comment. |
a2249b2
to
3fae0d7
Compare
@2opremio thanks with the hint... |
// returns some info like processes and connections | ||
type ProcReader interface { | ||
// Processes walks through the processes | ||
Processes(func(Process)) error |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
@tomwilkie or @peterbourgon could you please review this? |
@inercia Sure. Would you mind giving a short overview of what this PR does, and pointers to key types/functions/changes? (I know the basic context, just looking for your perspective.) |
654e5b0
to
62171ca
Compare
New: func() interface{} { | ||
return bytes.NewBuffer(make([]byte, 0, 5000)) | ||
}, | ||
} |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
@peterbourgon I have updated the PR description, so please let me know what you think about this... |
This is the latest profile graph from this branch (using go 1.5). Compared with the original graph in #284, we can see that the number of |
@inercia Thanks, that helps a lot. I'll give it a look. |
|
||
c.LocalAddress = dupIP(c.LocalAddress) | ||
c.RemoteAddress = dupIP(c.RemoteAddress) | ||
return c |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
The shape of it is good. Back to @inercia for those few comments (and rebasing, I guess). |
Some minor renames and cleanups.
👍 pending Coveralls. (Maybe Coveralls is broken?) |
@peterbourgon I think the coveralls hook has failed (the jobs is finisished, but the "Coverage pending" is still here). I'm merging.... |
The objective of this PR is to reduce the number of syscalls when collecting info from
/proc
. This PR does that by:/proc/*/[cmdline, comm, stat, fd/*]
,/proc/net/tcp*
) once per cycle (spy.interval
), parsing and caching the processes/connections information/proc/*/[cmdline, comm, stat]
so we do notopen()
/close()
these files so often.stat()
s when reading/proc
directoriesChanges:
/proc
has been proved fromprocspy
to/probe/proc
Walker
has been replaced by aproc.Reader
that provides bothProcesses()
andConnections()
. Users can walk the list of processes/connections in the same way by providing a function to these functions. ACachingReader
can be used for caching and getting this info, updated whenUpdate()
. The code for reading and parsing connection and processes has been simplified.CachingReader
is initialized in/probe/main.go
and used in bothendpoint.Reporter
andprocess.Reporter
for reporting about processed and connections, and updated periodically by callingUpdate()
everyspy.interval
seconds.Proc
andProcess
have been unified, and many things from/probe/process
have been moved to/probe/proc
This is part of the solution to #284