Skip to content
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

Using for + Supply.list results in high CPU usage #3629

Closed
p6rt opened this issue Dec 29, 2014 · 10 comments
Closed

Using for + Supply.list results in high CPU usage #3629

p6rt opened this issue Dec 29, 2014 · 10 comments

Comments

@p6rt
Copy link

p6rt commented Dec 29, 2014

Migrated from rt.perl.org#123515 (status was 'resolved')

Searchable as RT123515$

@p6rt
Copy link
Author

p6rt commented Dec 29, 2014

From @hoelzro

See the attached script. When running the script, CPU usage (as reported by top) is very high.

@p6rt
Copy link
Author

p6rt commented Dec 29, 2014

From @hoelzro

supply-cpu-test.p6

@p6rt
Copy link
Author

p6rt commented Dec 29, 2014

From @hoelzro

On Sun Dec 28 18​:05​:18 2014, rob@​hoelz.ro wrote​:

See the attached script. When running the script, CPU usage (as
reported by top) is very high.

For that matter, iterating over Supply.Channel results in high CPU usage as well.

@p6rt
Copy link
Author

p6rt commented Dec 29, 2014

From @hoelzro

On Sun Dec 28 18​:06​:47 2014, rob@​hoelz.ro wrote​:

On Sun Dec 28 18​:05​:18 2014, rob@​hoelz.ro wrote​:

See the attached script. When running the script, CPU usage (as
reported by top) is very high.

For that matter, iterating over Supply.Channel results in high CPU
usage as well.

So far, it seems to be Channel.list which is the culprit.

@p6rt
Copy link
Author

p6rt commented Dec 29, 2014

From @hoelzro

On Sun Dec 28 18​:08​:28 2014, rob@​hoelz.ro wrote​:

On Sun Dec 28 18​:06​:47 2014, rob@​hoelz.ro wrote​:

On Sun Dec 28 18​:05​:18 2014, rob@​hoelz.ro wrote​:

See the attached script. When running the script, CPU usage (as
reported by top) is very high.

For that matter, iterating over Supply.Channel results in high CPU
usage as well.

So far, it seems to be Channel.list which is the culprit.

Ok, any usage of earliest { ... } seems to go through a busy waiting loop unless a wait block is specified.

@p6rt
Copy link
Author

p6rt commented Dec 29, 2014

From @lizmat

On 29 Dec 2014, at 03​:05, Rob Hoelz (via RT) <perl6-bugs-followup@​perl.org> wrote​:

# New Ticket Created by Rob Hoelz
# Please include the string​: [perl #​123515]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=123515 >

See the attached script. When running the script, CPU usage (as reported by top) is very high.<supply-cpu-test.p6>

Looking deeper into the code, this appears to be caused by the implementation of “earliest” (former “winner”), which basically does a Thread.yield()​:

loop { Thread.yield }

This also eats 100% of one CPU. Not sure whether this is intended behaviour of Thread.yield or not. Having to use Thread.yield in “earliest” may also be sub-optimal.

Liz

@p6rt
Copy link
Author

p6rt commented Dec 29, 2014

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Dec 29, 2014

From @moritz

On 29.12.2014 13​:44, Elizabeth Mattijsen wrote​:

On 29 Dec 2014, at 03​:05, Rob Hoelz (via RT) <perl6-bugs-followup@​perl.org> wrote​:

# New Ticket Created by Rob Hoelz
# Please include the string​: [perl #​12351]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=123515 >

See the attached script. When running the script, CPU usage (as reported by top) is very high.<supply-cpu-test.p6>

Looking deeper into the code, this appears to be caused by the implementation of “earliest” (former “winner”), which basically does a Thread.yield()​:

loop { Thread.yield }

This also eats 100% of one CPU. Not sure whether this is intended behaviour of Thread.yield or not.

yield just tells the scheduler to prefer another thread; if no other
thread has work to do, it'll re-enter the thread that called yield,
causing 100% CPU usage.

Having to use Thread.yield in “earliest” may also be sub-optimal.

Agreed.

Cheers,
Moritz

@p6rt
Copy link
Author

p6rt commented Dec 29, 2014

From @hoelzro

Commit 49dac31 addresses this; since the subject of the ticket is resolved, I'm going to close this ticket and create a new one to address the busy waiting issue.

On Mon Dec 29 05​:00​:57 2014, moritz.lenz@​gmail.com wrote​:

On 29.12.2014 13​:44, Elizabeth Mattijsen wrote​:

On 29 Dec 2014, at 03​:05, Rob Hoelz (via RT) <perl6-bugs-
followup@​perl.org> wrote​:

# New Ticket Created by Rob Hoelz
# Please include the string​: [perl #​12351]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=123515 >

See the attached script. When running the script, CPU usage (as
reported by top) is very high.<supply-cpu-test.p6>

Looking deeper into the code, this appears to be caused by the
implementation of “earliest” (former “winner”), which basically does
a Thread.yield()​:

loop { Thread.yield }

This also eats 100% of one CPU. Not sure whether this is intended
behaviour of Thread.yield or not.

yield just tells the scheduler to prefer another thread; if no other
thread has work to do, it'll re-enter the thread that called yield,
causing 100% CPU usage.

Having to use Thread.yield in “earliest” may also be sub-optimal.

Agreed.

Cheers,
Moritz

@p6rt p6rt closed this as completed Dec 29, 2014
@p6rt
Copy link
Author

p6rt commented Dec 29, 2014

@hoelzro - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant