Skip to content

loop,threadpool: trace events#1815

Closed
jasnell wants to merge 4 commits into
libuv:masterfrom
jasnell:loop-stats-redo2
Closed

loop,threadpool: trace events#1815
jasnell wants to merge 4 commits into
libuv:masterfrom
jasnell:loop-stats-redo2

Conversation

@jasnell

@jasnell jasnell commented Apr 23, 2018

Copy link
Copy Markdown
Contributor

This is an alternative take to #1764 that uses a more trace-events style API as suggested by @bnoordhuis.

void start_cb(const uv_trace_info_t* info, void* data) {
  switch (info->type) {
    case UV_TRACE_TICK:
    // ...
  }
}

void end_cb(const uv_trace_info_t* info, void* data) {
  switch (info->type) {
    case UV_TRACE_TICK:
    // ...
  }
}

uv_loop_trace_t loop_config;
loop_config.start_cb = start_cb;
loop_config.end_cb = end_cb;
loop_config.data = &loop;

uv_loop_configure(&loop, UV_LOOP_TRACE, &loop_config);
void threadpool_trace_cb(const uv_trace_info_t* info, void* data) {
  const uv_threadpool_trace_info_t* tp_info =
    (const uv_threadpool_trace_info_t*)info;
  // ...
}

uv_threadpool_trace_t tp_config;
loop_config.cb = threadpool_trace_cb;
loop_config.data = &loop;

uv_loop_configure(&loop, UV_THREADPOOL_TRACE, &tp_config);

This approach greatly simplifies the record keeping required in V8 and minimizes the possible ABI breakages that could occur. It would integrate quite well with V8 Trace Events in Node.js but would increase the record keeping necessary there to integrate with things like the Performance API (record keeping would still be minimal).

The UV_LOOP_TRACE and UV_THREADPOOL_TRACE configuration options are separate largely to keep internal tracking simple. Loop tracing is specific to individual loops, while the threadpool may have multiple listeners. Keeping them separate allows for greatly simplified tracking without internals getting muddy.

@jasnell

jasnell commented Jun 1, 2018

Copy link
Copy Markdown
Contributor Author

Ping @bnoordhuis @cjihrig @evanlucas @saghul ... I'd like to close the loop on this soon, if at all possible. This is an alternate take on the ideas in #1764 that uses more of a trace-events style model (as suggested by @bnoordhuis)

@jasnell

jasnell commented Jun 22, 2018

Copy link
Copy Markdown
Contributor Author

Ping again... I'd like to get this landed. This particular version does require an ABI change and would require libuv 2.0... however, it would be possible to set this particular version up so that changes to uv_loop_t are not necessary by introducing a new static callback that can be set with a separate API (e.g. uv_set_trace_callback(cb) where the first argument passed to cb is the uv_loop_t. Could potentially make things easier for supporting multiple event_loops/isolates now that Workers have landed in Node.js core.

@jasnell

jasnell commented Jul 13, 2018

Copy link
Copy Markdown
Contributor Author

@cjihrig @evanlucas @saghul @bnoordhuis ... would it be possible to get some idea of when this may be looked at?

@santigimeno santigimeno left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the loop_trace test is failing locally:

not ok 139 - loop_trace
# exit code 6
# Output from process `loop_trace`:
# Assertion failed in test/test-loop-trace.c on line 129: saw_start_event & (1 << UV_TRACE_POLL)

Comment thread test/test-threadpool-trace.c Outdated
#define START_SIZE 8
static unsigned idle_max = 0;
static unsigned idle_min = 2 * START_SIZE;
static unsigned queued_max = 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to initialize static variables to zero

Comment thread test/test.gyp
'test-loop-close.c',
'test-loop-stop.c',
'test-loop-time.c',
'test-loop-trace.c',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test-threadpool-trace.c should be added too

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread test/runner.c Outdated
}

test_result = run_test(task->task_name, benchmark_output, current);
fflush(stderr);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this change belongs here.

Comment thread src/win/req-inl.h Outdated
uv_req_t* req;
uv_req_t* first;
uv_req_t* next;
size_t count = 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

separate declaration from assignment

Comment thread src/unix/core.c Outdated
QUEUE* q;
QUEUE pq;
uv__io_t* w;
size_t count = 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: separate declaration from assignment

Comment thread src/uv-common.c Outdated
}

void uv__trace_end(uv_loop_t* loop,
const uv_trace_info_t* info) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: this can go on 1 line only

Comment thread test/test-loop-trace.c Outdated
@@ -0,0 +1,148 @@
/* Copyright (c) 2014, Ben Noordhuis <info@bnoordhuis.nl>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the copyright to something like this.

Comment thread test/test-loop-trace.c Outdated
static size_t check_count = 0;
static size_t idle_count = 0;
static size_t prepare_count = 0;
static size_t pending_count = 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to initialize static variables to zero.

Comment thread src/unix/linux-core.c Outdated

if (timeout == 0)
if (timeout == 0) {
uv__trace_end(loop, (uv_trace_info_t*)&trace_info);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead of adding the uv__trace_end() call on every return, add a label and use goto.

Comment thread src/unix/internal.h
enum {
UV_LOOP_BLOCK_SIGPROF = 1
UV_LOOP_BLOCK_SIGPROF = 1,
UV_LOOP_TRACE_NOTIFY = 2

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see this flag being used in the code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

look in unix/loop.c ... it's set as a loop->flags... purely informational right now.

@jasnell

jasnell commented Aug 24, 2018

Copy link
Copy Markdown
Contributor Author

@santigimeno ... what platform are you testing on where it's failing locally? loop_trace is passing for me on Ubuntu so I'm not sure what's up.

@santigimeno

Copy link
Copy Markdown
Member

what platform are you testing on where it's failing locally? loop_trace is passing for me on Ubuntu so I'm not sure what's up.

@jasnell on OS X. I'll try to look at it.

@bnoordhuis bnoordhuis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've thought about this PR and I say let's not do this for now. Landing it very much complicates the thread pool redesign discussed in #1959. That's an important and long-standing issue.

What's more, if the pluggable thread pool approach goes through, which seems likely, the tracing functionality in libuv becomes obsolete. Node.js won't use it because it'll move to its own custom thread pool and other users are unlikely.

(Besides, such users can plug in their own thread pool with added instrumentation. To me that's a strictly superior option.)

@jasnell

jasnell commented Sep 2, 2018

Copy link
Copy Markdown
Contributor Author

That seems to only impact the threadpool aspect of this, not the loop tracing.

@davisjam

davisjam commented Sep 2, 2018

Copy link
Copy Markdown
Contributor

That seems to only impact the threadpool aspect of this, not the loop tracing.

I agree -- Node would still benefit from loop tracing. And I don't see a problem in supporting tracing in the default libuv threadpool, thus benefiting embedders who don't plug in their own TPs.

@bnoordhuis

Copy link
Copy Markdown
Member

That seems to only impact the threadpool aspect of this, not the loop tracing.

@jasnell It reminds me of the dtrace/systemtap probes I removed in cb51400. Lots of infrastructure and maintenance for something that was ultimately of marginal value.

They traced event loop ticks too but at least they were zero cost when disabled. This PR on the other hand adds some ever-present overhead.

And since it targets master and is a pretty big diff, it'll be an ongoing merge conflict magnet as long as the v1.x branch is alive.

I'm not really convinced it's worth it for those two (three?) reasons. I just can't get excited about it. Maybe other maintainers feel differently.

And I don't see a problem in supporting tracing in the default libuv threadpool

@davisjam I'm sympathetic to that argument but I don't think anyone asked for thread pool tracing except Node.js + derivatives, and I expect that for them it's only a stop-gap measure.

I'm open to reconsidering it if other users do pop up, however. It would be good to get more feedback on the API anyhow.

@pfreixes

pfreixes commented Feb 7, 2019

Copy link
Copy Markdown

Its a pity not having this PR, or at least the loop events, moving forward ..... what can we do ? or what is needed to justify the adoption of loop traces?

@stale

stale Bot commented Aug 10, 2019

Copy link
Copy Markdown

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale Bot added the stale label Aug 10, 2019
@stale stale Bot closed this Aug 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants