-
Notifications
You must be signed in to change notification settings - Fork 715
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
perf add timeout argument #736
Conversation
Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>
Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>
perf/reader.go
Outdated
@@ -162,6 +163,7 @@ type ReaderOptions struct { | |||
// Read will process data. Must be smaller than PerCPUBuffer. | |||
// The default is to start processing as soon as data is available. | |||
Watermark int | |||
TimeOut int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this option should have at least document what it is used for so users can reason about its impact. Also if there is a default value, it should be mentioned here as well I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With SetDeadline
this Option isn't used anymore.
Hi @xpu22, thanks for your PR! There was an earlier proposal for this in #523 The gist of the discussion is:
Please also add some unit tests and take a look at the failing CI: https://ebpf.semaphoreci.com/jobs/b80f08ab-6ffd-4473-8887-27ad0c4c0508#L572 |
|
Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>
https://ebpf.semaphoreci.com/jobs/690fd5ce-e7d0-4400-9f58-3da6f915e3a0#L573 is still failing. Please ping me explicitly when you're ready for another round of review. |
Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>
Hi @lmb please review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks for following up so quickly!
n, err := unix.EpollWait(p.epollFd, events, -1) | ||
msec := int(-1) | ||
if !deadline.IsZero() { | ||
msec = int(time.Until(deadline).Milliseconds()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug in my own code: this doesn't handle deadlines in the past or so far in the future that msec is overflowed.
I'll fix that up in a follow up.
perf/reader.go
Outdated
ErrClosed = os.ErrClosed | ||
errEOR = errors.New("end of ring") | ||
ErrClosed = os.ErrClosed | ||
ErrTimeOut = os.ErrDeadlineExceeded |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This alias isn't necessary. Just document that os.ErrDeadlineExceeded
is returned.
perf/reader.go
Outdated
@@ -162,6 +163,7 @@ type ReaderOptions struct { | |||
// Read will process data. Must be smaller than PerCPUBuffer. | |||
// The default is to start processing as soon as data is available. | |||
Watermark int | |||
TimeOut int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With SetDeadline
this Option isn't used anymore.
perf/reader.go
Outdated
@@ -133,7 +135,8 @@ func readRawSample(rd io.Reader, buf, sampleBuf []byte) ([]byte, error) { | |||
// Reader allows reading bpf_perf_event_output | |||
// from user space. | |||
type Reader struct { | |||
poller *epoll.Poller | |||
poller *epoll.Poller | |||
timeOut time.Time |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: deadline time.Time
.
perf/reader.go
Outdated
@@ -299,14 +316,15 @@ func (pr *Reader) Read() (Record, error) { | |||
func (pr *Reader) ReadInto(rec *Record) error { | |||
pr.mu.Lock() | |||
defer pr.mu.Unlock() | |||
defer func() { pr.timeOut = time.Time{} }() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So net.Conn
does not automatically clear the deadline: https://pkg.go.dev/net#Conn Unless there is a strong reason to do this here I'd suggest that we also don't clear it.
perf/reader.go
Outdated
@@ -280,6 +285,18 @@ func (pr *Reader) Close() error { | |||
return nil | |||
} | |||
|
|||
// SetDeadline the Read timeout |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// SetDeadline the Read timeout | |
// SetDeadline controls how long Read and ReadInto will block waiting for samples. | |
// | |
// Passing a zero time.Time will remove the deadline. |
perf/reader.go
Outdated
// SetDeadline the Read timeout | ||
// | ||
// If this function was not invoked, the Read, ReadInto | ||
// will be blocked until there are at least Watermark |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is slightly misleading: adding a timeout / deadline doesn't change how Watermark
works.
perf/reader_test.go
Outdated
@@ -58,6 +58,10 @@ func TestPerfReader(t *testing.T) { | |||
if record.CPU < 0 { | |||
t.Error("Record has invalid CPU number") | |||
} | |||
|
|||
rd.SetDeadline(time.Now().Add(100 * time.Millisecond)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: you can make the timeout very short, like a millisecond or so. It'll save us a bit of time when running ht test.
internal/epoll/poller.go
Outdated
@@ -138,6 +144,10 @@ func (p *Poller) Wait(events []unix.EpollEvent) (int, error) { | |||
return 0, err | |||
} | |||
|
|||
if n == 0 && msec != -1 { | |||
return 0, os.ErrDeadlineExceeded |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should wrap the error here, otherwise we return a naked ErrDeadlineExceeded.
return 0, os.ErrDeadlineExceeded | |
return 0, fmt.Errorf("poll: %w", os.ErrDeadlineExceeded) |
Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>
Cool, adding the timeout of ebpf-perf is very necessary! The new Read() API is as follows: func (pr *Reader) ReadWithContext(ctx context.Context) (Record, error) |
We have, but IMO the performance characteristics of Could you give a practical use case for it? In any case, I would suggest we take this discussion to a dedicated issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for finishing this work, I was waiting for you to ping me for another review. Sorry it took a while.
No description provided.