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

Issue 148113003: forwarder2: Make the Forwarder instances operate on a single thread. (Closed)

Created:
6 years, 11 months ago by Philippe
Modified:
6 years, 10 months ago
Reviewers:
pasko, bulach, qsr, digit1
CC:
chromium-reviews, craigdh+watch_chromium.org, bulach+watch_chromium.org, yfriedman+watch_chromium.org, ilevy-cc_chromium.org, klundberg+watch_chromium.org, frankf+watch_chromium.org
Visibility:
Public.

Description

forwarder2: Make the Forwarder instances operate on a single thread. The Forwarder class used to operate on its own internal thread. This was leading to e.g. 256 threads being spawned since Chrome keeps a lot of sockets around in its socket pool. This CL makes the ForwarderManager have an internal thread performing a single select() on all the socket file descriptors and it notifies all the Forwarder instances when some events occur. The fact that ForwarderManager has an internal thread that joins on destruction also makes the interactions between ForwarderManager and its clients much simpler. In particular it allows us to remove its ref-counted thread-safe delegate. This CL should make the device_forwarder daemon more lightweight and make the results in page_cyclers hopefully more stable. The internal buffer used to forward the traffic is also shrunk to 32 KBytes since 128 KBytes was way too big (read() rarely returns more than 16 KBytes). BUG=332403 Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=247694

Patch Set 1 #

Total comments: 2

Patch Set 2 : Address Benjamin's offline comments #

Total comments: 2

Patch Set 3 : Address Benjamin's comments #

Patch Set 4 : Move |kBufferSize| to an anonymous namespace #

Patch Set 5 : Create ScopedClosureRunner later #

Total comments: 7

Patch Set 6 : Address David's comment #

Unified diffs Side-by-side diffs Delta from patch set Stats (+175 lines, -211 lines) Patch
M tools/android/forwarder2/device_listener.h View 1 chunk +0 lines, -2 lines 0 comments Download
M tools/android/forwarder2/forwarder.h View 1 chunk +21 lines, -28 lines 0 comments Download
M tools/android/forwarder2/forwarder.cc View 1 2 3 5 chunks +34 lines, -76 lines 0 comments Download
M tools/android/forwarder2/forwarders_manager.h View 1 2 3 4 5 1 chunk +13 lines, -44 lines 0 comments Download
M tools/android/forwarder2/forwarders_manager.cc View 1 2 3 4 1 chunk +93 lines, -52 lines 0 comments Download
M tools/android/forwarder2/host_controller.h View 1 chunk +0 lines, -8 lines 0 comments Download
M tools/android/forwarder2/pipe_notifier.h View 1 chunk +2 lines, -0 lines 0 comments Download
M tools/android/forwarder2/pipe_notifier.cc View 1 1 chunk +12 lines, -1 line 0 comments Download

Messages

Total messages: 12 (0 generated)
Philippe
Sorry David for bothering you with forwarder2 again :) Marcus is OOO until next week ...
6 years, 11 months ago (2014-01-27 10:31:39 UTC) #1
qsr
LGTM with nits. https://codereview.chromium.org/148113003/diff/1/tools/android/forwarder2/forwarder.cc File tools/android/forwarder2/forwarder.cc (right): https://codereview.chromium.org/148113003/diff/1/tools/android/forwarder2/forwarder.cc#newcode207 tools/android/forwarder2/forwarder.cc:207: char buffer_[32 * 1024]; why getting ...
6 years, 11 months ago (2014-01-27 13:28:28 UTC) #2
Philippe
Thanks Benjamin! https://codereview.chromium.org/148113003/diff/1/tools/android/forwarder2/forwarder.cc File tools/android/forwarder2/forwarder.cc (right): https://codereview.chromium.org/148113003/diff/1/tools/android/forwarder2/forwarder.cc#newcode207 tools/android/forwarder2/forwarder.cc:207: char buffer_[32 * 1024]; On 2014/01/27 13:28:29, ...
6 years, 11 months ago (2014-01-27 13:41:35 UTC) #3
pasko
lgtm Though I looked at forwarder2 code the first time, learned much more than I ...
6 years, 11 months ago (2014-01-27 16:59:01 UTC) #4
Philippe
Adding Marcus since he's Out Of the London Office and not Out Of the Office ...
6 years, 11 months ago (2014-01-28 08:59:09 UTC) #5
pasko
https://codereview.chromium.org/148113003/diff/140002/tools/android/forwarder2/forwarders_manager.cc File tools/android/forwarder2/forwarders_manager.cc (right): https://codereview.chromium.org/148113003/diff/140002/tools/android/forwarder2/forwarders_manager.cc#newcode122 tools/android/forwarder2/forwarders_manager.cc:122: if (!forwarder->IsClosed()) { On 2014/01/28 08:59:09, Philippe wrote: > ...
6 years, 10 months ago (2014-01-28 10:48:55 UTC) #6
digit1
lgtm - I like it :-) https://codereview.chromium.org/148113003/diff/140002/tools/android/forwarder2/forwarders_manager.cc File tools/android/forwarder2/forwarders_manager.cc (right): https://codereview.chromium.org/148113003/diff/140002/tools/android/forwarder2/forwarders_manager.cc#newcode103 tools/android/forwarder2/forwarders_manager.cc:103: base::ScopedClosureRunner wait_for_events_soon( Can ...
6 years, 10 months ago (2014-01-28 17:28:32 UTC) #7
qsr
https://codereview.chromium.org/148113003/diff/140002/tools/android/forwarder2/forwarders_manager.cc File tools/android/forwarder2/forwarders_manager.cc (right): https://codereview.chromium.org/148113003/diff/140002/tools/android/forwarder2/forwarders_manager.cc#newcode103 tools/android/forwarder2/forwarders_manager.cc:103: base::ScopedClosureRunner wait_for_events_soon( On 2014/01/28 17:28:33, digit1 wrote: > Can ...
6 years, 10 months ago (2014-01-29 09:30:17 UTC) #8
Philippe
Thanks guys! https://codereview.chromium.org/148113003/diff/140002/tools/android/forwarder2/forwarders_manager.h File tools/android/forwarder2/forwarders_manager.h (right): https://codereview.chromium.org/148113003/diff/140002/tools/android/forwarder2/forwarders_manager.h#newcode18 tools/android/forwarder2/forwarders_manager.h:18: class ForwardersManager { On 2014/01/28 17:28:33, digit1 ...
6 years, 10 months ago (2014-01-29 10:50:03 UTC) #9
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/pliard@chromium.org/148113003/350001
6 years, 10 months ago (2014-01-29 10:50:15 UTC) #10
commit-bot: I haz the power
Change committed as 247694
6 years, 10 months ago (2014-01-29 16:15:27 UTC) #11
digit1
6 years, 10 months ago (2014-01-30 18:19:11 UTC) #12
Message was sent while issue was closed.
On 2014/01/29 09:30:17, qsr wrote:
>
https://codereview.chromium.org/148113003/diff/140002/tools/android/forwarder...
> File tools/android/forwarder2/forwarders_manager.cc (right):
> 
>
https://codereview.chromium.org/148113003/diff/140002/tools/android/forwarder...
> 
>  Given that this is only called when select returns and so, before some I/O,
> this is far from being a busy loop. Starting to use a custom thread and custom
> message passing for this seem to be a lot of effort for a gain that is not
> really evident at this point.

This is going to happen anytime you're going to either read or write a packet,
which can be frequent when transferring large amounts of data. I don't think it
will impact performance much, but I fear this may slightly increase variability
of the results though. Especially since this is used both on the device and on
the host at the same time during normal operations.

However, this is your code now, please do as you wish, but keep this in mind in
case you see a real effect on measurements ;-)

Powered by Google App Engine
This is Rietveld 408576698