Discussion:
[Larceny-users] freezing for garbage collection?
Matthew Parker
2008-03-04 05:34:23 UTC
Permalink
Hi, I'm running larceny for x86 with the native compiler.

I have used the foreign interface to connect it to a module I have that
lets you control the artificial intelligence of a Quake 2 client (quake2
is a
first person shooter game). The module runs the game at 40 frames per
second, which doesn't use much CPU, and for every frame it does a
call-back into larceny and runs a scheme function that controls the AI.

I did this in chicken scheme and it worked very well, but I decided to
switch to larceny since chicken is quite slow in comparison. I've got it
all working
except I notice that every so often the game will freeze up for a split
second, noticably, and then resume its normal speed. Is this due to the
garbage collector? Is there any way to fix this by changing the gc
settings, or by running things in a thread?

Thank you,
Matt
William D Clinger
2008-03-04 19:02:59 UTC
Permalink
Post by Matthew Parker
I did this in chicken scheme and it worked very well, but
I decided to switch to larceny since chicken is quite slow
in comparison. I've got it all working except I notice
that every so often the game will freeze up for a split
second, noticably, and then resume its normal speed. Is
this due to the garbage collector?
Probably.

I would generally expect Larceny's garbage collector
to perform better than Chicken's, but Larceny's heap
image might be substantially larger than Chicken's or
its default gc settings may be sub-optimal for your
application.
Post by Matthew Parker
Is there any way to fix this by changing the gc
settings, or by running things in a thread?
There are several gc-related things you can try. The
first step is to see which settings make a noticeable
difference. Here's what I'd suggest:

% larceny -size0 4M -areas 3 -nocontract

If that helps, then you can determine which of the
three things are helping ("-size0 4M", "-areas 3",
and "-nocontract") by leaving them out. If one of
the first two things help, then you can try increasing
the size of the nursery and/or ephemeral area still
further.

For an explanation of these settings, type

% larceny --wizard

Although you don't ordinarily want to use the --annoy-user
switch, you may find that it helps you to understand the
effect of other switches.

With Larceny's current garbage collectors, there is no
way to avoid an occasional long pause, but at least some
of the settings suggested above should make those pauses
less frequent.

Will
David Rush
2008-03-04 20:27:00 UTC
Permalink
Post by William D Clinger
With Larceny's current garbage collectors, there is no
way to avoid an occasional long pause, but at least some
of the settings suggested above should make those pauses
less frequent.
Given that Larceny was originally meant to be a platform for trying various
GC schemes (no pun intended) is it perhaps time to find a gifted student in
need of a senior project to write a bounded-incremental collector? My read
of the literature is that such a collector is a fairly well-solved
problem...

david rush
--
Once you label me, you negate me
- Soren Kierkegaard
Matthew Parker
2008-03-04 23:08:10 UTC
Permalink
Will running the game in a thread work? I suppose I'd have two threading
options; either running it with pthread through the C library, or using
the threading functions that appear in the MzScheme section.

I tried running it with your options and there were still pauses (less
frequent, but just as large delays). Could I set it so there are frequent
small garbage collections, like one after every frame of the game, with
no apparent pause?
Perhaps I could manually call the collector after every frame? I really
can't have any noticeable pauses in the game since it will mess up the
AI's behavior.

Matt
Post by William D Clinger
Post by Matthew Parker
I did this in chicken scheme and it worked very well, but
I decided to switch to larceny since chicken is quite slow
in comparison. I've got it all working except I notice
that every so often the game will freeze up for a split
second, noticably, and then resume its normal speed. Is
this due to the garbage collector?
Probably.
I would generally expect Larceny's garbage collector
to perform better than Chicken's, but Larceny's heap
image might be substantially larger than Chicken's or
its default gc settings may be sub-optimal for your
application.
Post by Matthew Parker
Is there any way to fix this by changing the gc
settings, or by running things in a thread?
There are several gc-related things you can try. The
first step is to see which settings make a noticeable
% larceny -size0 4M -areas 3 -nocontract
If that helps, then you can determine which of the
three things are helping ("-size0 4M", "-areas 3",
and "-nocontract") by leaving them out. If one of
the first two things help, then you can try increasing
the size of the nursery and/or ephemeral area still
further.
For an explanation of these settings, type
% larceny --wizard
Although you don't ordinarily want to use the --annoy-user
switch, you may find that it helps you to understand the
effect of other switches.
With Larceny's current garbage collectors, there is no
way to avoid an occasional long pause, but at least some
of the settings suggested above should make those pauses
less frequent.
Will
William D Clinger
2008-03-04 20:37:26 UTC
Permalink
Post by David Rush
Given that Larceny was originally meant to be a platform for trying various
GC schemes (no pun intended) is it perhaps time to find a gifted student in
need of a senior project to write a bounded-incremental collector?
Last week, after giving a talk on that very problem for
a meeting of our local student chapter of the ACM, I met
several gifted students who seemed to have some interest.
Post by David Rush
My read of the literature is that such a collector is a fairly well-solved
problem...
Real-time collectors generally sacrifice considerable
throughput. Maintaining throughput while bounding the
worst-case pause time remains a goal of current research.

Will
William D Clinger
2008-03-05 00:17:46 UTC
Permalink
Post by Matthew Parker
Will running the game in a thread work?
No.
Post by Matthew Parker
I tried running it with your options and there were still pauses (less
frequent, but just as large delays).
That will be a problem with all of Larceny's current
garbage collectors (and with other stop-the-world
collectors, including Chicken's). Generational
collectors make the delays less frequent, but don't
do anything to reduce their duration.

So far as I know, there are no implementations of
Scheme whose garbage collectors can meet your needs.
Marc Feeley has said he was working on a real-time
collector for Gambit, but I don't know its current
status. We are working on a new collector for
Larceny that should meet your requirements, but it
isn't finished yet.
Post by Matthew Parker
Could I set it so there are frequent
small garbage collections, like one after every frame of the game, with
no apparent pause?
The settings I gave you already increase the frequency
of minor collections, and reduce the duration of most
major collections, but there is currently no way to
eliminate all of Larceny's full collections.
Post by Matthew Parker
Perhaps I could manually call the collector after every frame?
That won't help either.
Post by Matthew Parker
I really
can't have any noticeable pauses in the game since it will mess up the
AI's behavior.
We understand the problem. We have designed a collector
that should work for you, but we don't expect to release
it until this fall. If you are willing to test the new
collector for us, however, then we might have something
for you to try a little sooner.

Will
Matthew Parker
2008-03-05 01:28:48 UTC
Permalink
Ah, ok, well that's good new that you are putting in a new collector. I
would like to test it for you, as well.

I have been using chicken scheme already and it doesn't ever freeze the
screen from garbage collection (I don't know why not). It also happens
to be quite slow compared to larceny or even maybe gambit-c. I tried
using gambit once and it did the same freezes.

Tell me when you've got something you'd like me to test. I'll go back to
using chicken until then, I suppose.

Matt
Post by William D Clinger
Post by Matthew Parker
Will running the game in a thread work?
No.
Post by Matthew Parker
I tried running it with your options and there were still pauses (less
frequent, but just as large delays).
That will be a problem with all of Larceny's current
garbage collectors (and with other stop-the-world
collectors, including Chicken's). Generational
collectors make the delays less frequent, but don't
do anything to reduce their duration.
So far as I know, there are no implementations of
Scheme whose garbage collectors can meet your needs.
Marc Feeley has said he was working on a real-time
collector for Gambit, but I don't know its current
status. We are working on a new collector for
Larceny that should meet your requirements, but it
isn't finished yet.
Post by Matthew Parker
Could I set it so there are frequent
small garbage collections, like one after every frame of the game, with
no apparent pause?
The settings I gave you already increase the frequency
of minor collections, and reduce the duration of most
major collections, but there is currently no way to
eliminate all of Larceny's full collections.
Post by Matthew Parker
Perhaps I could manually call the collector after every frame?
That won't help either.
Post by Matthew Parker
I really
can't have any noticeable pauses in the game since it will mess up the
AI's behavior.
We understand the problem. We have designed a collector
that should work for you, but we don't expect to release
it until this fall. If you are willing to test the new
collector for us, however, then we might have something
for you to try a little sooner.
Will
William D Clinger
2008-03-05 15:02:46 UTC
Permalink
Post by Matthew Parker
I have been using chicken scheme already and it doesn't ever freeze the
screen from garbage collection (I don't know why not). It also happens
to be quite slow compared to larceny or even maybe gambit-c. I tried
using gambit once and it did the same freezes.
In that case, there is one more thing you should try.

Chicken doesn't attempt to collect compiled code or
static data. Larceny does, and I think that's the
most likely reason you're noticing these "freezes"
in Larceny but not Chicken. You can prevent Larceny
from attempting to collect your compiled code and
static data by creating your own heap image that
contains your entire program, like this:

% larceny -stopcopy
Post by Matthew Parker
(load "myprogram") ; load your entire program,
; but don't start it
Post by Matthew Parker
(dump-interactive-heap "myprogram.heap")
(exit)
(Instead of dump-interactive-heap, you might prefer to
use dump-heap; see the Larceny User Manual.)

Then create a split heap:

% larceny -heap myprogram.heap -reorganize-and-dump

That creates myprogram.heap.split, which you can rename
and use as your initial heap:

% mv myprogram.heap.split mypgm
% larceny -heap mypgm -areas 3

If that doesn't help, then we might have been wrong in
thinking the freezes are caused by garbage collection.

Will

Loading...