Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Issue 2602243002: Use TaskScheduler instead of WorkerPool in multi_threaded_cert_verifier.cc. (Closed)

Created:
3 years, 11 months ago by fdoray
Modified:
3 years, 10 months ago
Reviewers:
gab, eroman, Ryan Sleevi
CC:
chromium-reviews, cbentzel+watch_chromium.org
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Use TaskScheduler instead of WorkerPool in multi_threaded_cert_verifier.cc. The following traits are used: Priority: Inherited (default) The priority is inherited from the calling context (i.e. TaskTraits are initialized with the priority of the current task). Shutdown behavior: CONTINUE_ON_SHUTDOWN Tasks posted with this mode which have not started executing before shutdown is initiated will never run. Tasks with this mode running at shutdown will be ignored (the worker will not be joined). Note: Tasks that were previously posted to base::WorkerPool should use this shutdown behavior because this is how base::WorkerPool handles all its tasks. May Block: Tasks posted with MayBlock() may block. This includes but is not limited to tasks that wait on synchronous file I/O operations: read or write a file from disk, interact with a pipe or a socket, rename or delete a file, enumerate files in a directory, etc. This trait isn't required for the mere use of locks. BUG=659191

Patch Set 1 #

Patch Set 2 : add ScopedTaskSchedulers #

Patch Set 3 : add ScopedTaskSchedulers #

Patch Set 4 : Fix Linux tests. #

Patch Set 5 : Remove ScopedTaskScheduler from TokenBindingURLRequestTest #

Patch Set 6 : self-review #

Total comments: 3
Unified diffs Side-by-side diffs Delta from patch set Stats (+84 lines, -43 lines) Patch
M net/cert/multi_threaded_cert_verifier.cc View 1 2 3 5 chunks +24 lines, -25 lines 0 comments Download
M net/cert/multi_threaded_cert_verifier_unittest.cc View 1 2 chunks +8 lines, -1 line 0 comments Download
M net/cert_net/nss_ocsp_unittest.cc View 1 2 3 2 chunks +6 lines, -0 lines 1 comment Download
M net/quic/chromium/quic_stream_factory_test.cc View 1 2 2 chunks +5 lines, -0 lines 2 comments Download
M net/test/embedded_test_server/embedded_test_server_unittest.cc View 1 2 5 chunks +15 lines, -3 lines 0 comments Download
M net/url_request/url_fetcher_impl_unittest.cc View 1 4 chunks +6 lines, -3 lines 0 comments Download
M net/url_request/url_request_unittest.cc View 1 2 3 4 5 6 chunks +15 lines, -10 lines 0 comments Download
M net/websockets/websocket_end_to_end_test.cc View 1 3 chunks +5 lines, -1 line 0 comments Download

Messages

Total messages: 37 (28 generated)
fdoray
PTAL
3 years, 10 months ago (2017-02-06 21:35:29 UTC) #26
eroman
+rsleevi https://codereview.chromium.org/2602243002/diff/100001/net/quic/chromium/quic_stream_factory_test.cc File net/quic/chromium/quic_stream_factory_test.cc (right): https://codereview.chromium.org/2602243002/diff/100001/net/quic/chromium/quic_stream_factory_test.cc#newcode4976 net/quic/chromium/quic_stream_factory_test.cc:4976: base::test::ScopedTaskScheduler scoped_task_scheduler( What is the recipe for including ...
3 years, 10 months ago (2017-02-07 22:45:45 UTC) #28
Ryan Sleevi
CC'ing gab. I started partially through, but I think overall this is probably something we ...
3 years, 10 months ago (2017-02-07 22:52:09 UTC) #30
gab
On 2017/02/07 22:52:09, Ryan Sleevi wrote: > CC'ing gab. > > I started partially through, ...
3 years, 10 months ago (2017-02-08 16:01:42 UTC) #31
Ryan Sleevi
On 2017/02/08 16:01:42, gab wrote: > That's unfortunate. //net is the only component in the ...
3 years, 10 months ago (2017-02-08 16:09:20 UTC) #32
Ryan Sleevi
On 2017/02/08 16:01:42, gab wrote: > That's unfortunate. //net is the only component in the ...
3 years, 10 months ago (2017-02-08 16:09:21 UTC) #33
gab
On 2017/02/08 16:09:21, Ryan Sleevi wrote: > On 2017/02/08 16:01:42, gab wrote: > > That's ...
3 years, 10 months ago (2017-02-08 16:45:31 UTC) #34
Ryan Sleevi
On 2017/02/08 16:45:31, gab wrote: > It seems the need for ScopedAsyncTaskScheduler in this CL ...
3 years, 10 months ago (2017-02-08 16:56:33 UTC) #35
gab
3 years, 10 months ago (2017-02-08 17:44:22 UTC) #36
On 2017/02/08 16:56:33, Ryan Sleevi wrote:
> On 2017/02/08 16:45:31, gab wrote:
> > It seems the need for ScopedAsyncTaskScheduler in this CL was caused by a
task
> > blocking on a WaitableEvent to be signaled. Whoever signals the event could
> > instead notify observers which are responsible for dispatching the work
(i.e.
> > dispatch the work when ready instead of ahead of time + blocking on
dependent
> > result).
> 
> Ah, ok. Perhaps you may not have looked closely (hopefully that doesn't come
off
> negative! I do it all the time in reviews), or perhaps the code was
> underdocumented (if so, we can fix that! Let me know :D), but the reason the
> code blocks on a WaitableEvent is that we're implementing a third-party
library
> delegate interface (that is, 3P library calls into us when it needs us to
> perform some work), and the 3P library requires that we MUST complete that
work
> synchronously.
> 
> Since the work to be completed synchronously is "Perform a network request",
and
> since we don't and can't block the IO thread for that, that's part of why the
> call *into* the 3P library (which will then call back into us) is done on a
> worker thread; in effect, the worker thread MUST block on the IO thread,
because
> of the 3P API contract, and the IO thread MUST NOT block on the 3P API call,
> which is why the worker thread :)
> 
> > I understand that in your case the work is mostly blocking so each thread is
> > very low overhead (and that one-thread-per-blocking-async-task is a common
> > paradigm on POSIX). But TaskScheduler aims to unify the place where such
> > implementation details decisions are taken and implemented (e.g. one thread
> per
> > blocking task on POSIX). There were previously many users of
base::WorkerPool
> > and other APIs hacking their own way at what they wanted from the system
(e.g.
> > v8 posting |num_core| computing tasks to base::WorkerPool and using those as
> > "workers" precisely to avoid flooding with |num_tasks| threads). We should
> > decide what's best on a given platform, implement it in one place
> > (TaskScheduler) and have every component benefit from it.
> 
> Right, and for some cases (e.g. calling a blocking system API), I totally
agree
> that having a centralized place to manage those growth and scaling and
> distribution decisions is not a bad outcome. It may be that some of the
> disconnect comes from the fact that most of the WorkerPool usage in //net (at
> least related to certificates or crypto) is coming from the fact that we have
a
> sequence of calls such as
> 
> Chromium -> 3P library blocking API call
> 
> But we also have
> 
> 3P library -> Chromium implementing a 'blocking' method as part of the 3P API
> 
> That is, NSS provides hooks for UI decisions (which must be implemented using
a
> blocking/synchronous method), and for network fetching (which must be
> implemented using a blocking/synchronous method). Unlike interactions with
other
> 3P libraries, like, say, glib, NSS does not have any notion of message loop or
> task queue, so there's no way we can indicate an asynchronous completion.
> 
> It used to be more substantial, but our shift to BoringSSL has allowed us to
> make (at least, for other platforms) these interaction points async methods;
> that is, when BoringSSL calls into Chromium, we can say "We'll get back to you
> later", which allows BoringSSL's state machine to pause until we (Chromium)
> complete the work _and then signal_ to BoringSSL that the work has completed.
> 
> I don't know how well I communicated that pattern/paradigm in the past, but
> since you mentioned observers above, I suspect I didn't do so cleanly.
> 
> There's also a few interaction points we have on Windows, but luckily, none of
> the interfaces we're implementing would require us to block, so we're able to
> just synchronously complete the work. On macOS, we largely just suffer from
the
> "Chromium -> 3P library blocking API call" pattern (meaning we might be able
to
> use TaskScheduler there), except that the way it's implemented varies across
our
> supported macOS releases with respect to how the library internally implements
> its task queue, so we can't quite generalize it safely.
> 
> Does that help document why the unfortunate sadness?

Aaaaaaah, ok, I think I finally understand your use case :) (I had indeed not
read the code closely enough)

This is very specific to //net per having to deal with such third-party APIs and
isn't an issue anywhere else in our codebase. Let's move base::WorkerPool to
net::WorkerPool when //net becomes its only user and we can eventually discuss
how TaskScheduler could support these use cases as well.

Thanks,
Gab

Powered by Google App Engine
This is Rietveld 408576698