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

Garbage collection of completed tasks #113

Closed
danichcr72 opened this issue Feb 23, 2017 · 6 comments
Closed

Garbage collection of completed tasks #113

danichcr72 opened this issue Feb 23, 2017 · 6 comments

Comments

@danichcr72
Copy link

Hi,

Another general issue that appeared in my experience with fiber is that completed tasks do not release their memory until the dispatcher/system fiber runs.

The dispatcher fiber is not scheduled in all (?) / most(?) schedulers unless there are no application fibers pending. It would be great to provide another mechanism to garbage collect completed tasks, either by the user calling a function or by having the dispatcher fiber scheduled with some other priority.

Thanks,

Daniel Chavarria
Trovares Inc.

@olk
Copy link
Member

olk commented Feb 24, 2017

One of the tasks of the dispatcher-fiber is to release terminated worker-fibers (== fibers created by the user-code). The dispatcher-fiber is the first fiber in the ready-queue when the application/thread starts. It always enqueues itself before it hands-over to another worker-fiber (dequeued from the ready-queue).
So the dispatcher-fiber should be executed multiple times in your app.

@danichcr72
Copy link
Author

Thanks for the quick reply. I can see that the dispatcher fiber is scheduled to run, however in the shared_work scheduler at least, it does not run unless there are no worker fibers pending:

if ( ! rqueue_.empty() ) { /*<
        pop an item from the ready queue
    >*/
    ctx = rqueue_.front();
    rqueue_.pop_front();
    lk.unlock();
    BOOST_ASSERT( nullptr != ctx);
    context::active()->attach( ctx); /*<
        attach context to current scheduler via the active fiber
        of this thread
    >*/
} else {
    lk.unlock();
    if ( ! lqueue_.empty() ) { /*<
            nothing in the ready queue, return main or dispatcher fiber
        >*/

@olk
Copy link
Member

olk commented Feb 24, 2017

right - shared_work was previously in the examples , so I missed the implementation details

@olk
Copy link
Member

olk commented Apr 2, 2017

releated to #112

@olk
Copy link
Member

olk commented Apr 2, 2017

The problem is that the dispatcher-fiber is not correctly scheduled in the shared_work algo.
If you take a look at work_stealgin algo (branch develop) you see that the dipatcher-fiber is scheduled like in round_robin.
I suggest to switch to work_stealing because it is faster (locality of data) than shared_work.
Otherwise shared_work needs some counters that manage teh scheduling of main-/dispatcher-fiber ...

@olk
Copy link
Member

olk commented Apr 30, 2017

use work-stealing scheduler instead

@olk olk closed this as completed Apr 30, 2017
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

2 participants