Fork me on GitHub

taking the new and shiny Mono Simple Generational Garbage Collector ( mono-sgen ) for a walk…

“Mono is a soft­ware plat­form designed to allow devel­op­ers to eas­ily cre­ate cross plat­form appli­ca­tions. It is an open source imple­men­ta­tion of Microsoft’s .Net Frame­work based on the ECMA stan­dards for C# and the Com­mon Lan­guage Run­time. We feel that by embrac­ing a suc­cess­ful, stan­dard­ized soft­ware plat­form, we can lower the bar­ri­ers to pro­duc­ing great appli­ca­tions for Linux.” (Source)

In other words: Mono is the plat­form which is needed to run the sones GraphDB on any oper­at­ing sys­tem dif­fer­ent from Win­dows. It included the so called “Mono Run­time” which basi­cally is the place where the sones GraphDB “lives” to do it’s work.

Being a run­time is not an easy task. In fact it’s abil­i­ties and algo­rithms take a deep impact on the per­for­mance of the appli­ca­tion that runs on top of it. When it comes to all things related to mem­ory man­age­ment the garbage col­lec­tor is one of the most impor­tant parts of the runtime:

“In com­puter sci­ence, garbage col­lec­tion (GC) is a form of auto­matic mem­ory man­age­ment. It is a spe­cial case of resource man­age­ment, in which the lim­ited resource being man­aged is mem­ory. The garbage col­lec­tor, or just col­lec­tor, attempts to reclaim garbage, or mem­ory occu­pied by objects that are no longer in use by the pro­gram. Garbage col­lec­tion was invented by John McCarthy around 1959 to solve prob­lems in Lisp.” (Source)

The Mono run­time has always used a sim­ple garbage col­lec­tor imple­men­ta­tion called “Boehm-Demers-Weiser con­ser­v­a­tive garbage col­lec­tor”. This imple­men­ta­tion is mainly known for its sim­plic­ity. But as more and more data inten­sive appli­ca­tions, like the sones GraphDB, started to appear this type of garbage col­lec­tor wasn’t quite up to the job.

So the Mono team started the devel­op­ment on a Sim­ple Gen­er­a­tional Garbage col­lec­tor whose prop­er­ties are:

  • Two gen­er­a­tions.
  • Mostly pre­cise scan­ning (stacks and reg­is­ters are scanned conservatively).
  • Copy­ing minor collector.
  • Two major col­lec­tors: Copy­ing and Mark&Sweep.
  • Per-thread frag­ments for fast per-thread allocation.
  • Uses write bar­ri­ers to min­i­mize the work done on minor collections.

To fully under­stand what this new garbage col­lec­tor does you most prob­a­bly need to read this and take a look inside the mono s-gen garbage col­lec­tor code.

So what we did was tak­ing the old and the new garbage col­lec­tor and our GraphDB and let them iter­ate through an auto­mated test which basi­cally runs 200.000 insert queries which result in more than 3.4 mil­lion edges between more than 120.000 objects. The results were impres­sive when we com­pared the old mono garbage col­lec­tor to the new mono-sgen garbage collector.

When we plot­ted a basic graph of the mea­sure­ments we got that:

monovsmono-sgen

On the x-axis it’s the num­ber of inserts and on the y-axis it’s the time it takes to answer one query. So it’s a great mea­sure­ment to see how big actu­ally the impact of the garbage col­lec­tor is on a com­plex appli­ca­tion like the sones GraphDB.

The red curve is the old Boehm-Demers-Weiser con­ser­v­a­tive garbage col­lec­tor built into cur­rent sta­ble ver­sions of mono. The blue curve is the new SGEN garbage col­lec­tor which can be used by invok­ing Mono using the “mono-sgen” com­mand instead of the “mono” com­mand. Since mono-sgen is not included in any sta­ble build yet it’s nec­es­sary to build mono from source. We doc­u­mented how to do that here.

So what are we actu­ally see­ing in the chart? We can see that mono-sgen draws a fairly lin­ear line in com­par­i­son to the old mono garbage col­lec­tor. It’s easy to tell why the blue curve is ris­ing – it’s because the num­ber of objects is grow­ing with each mil­lisec­ond. The blue line is just what we are expect­ing from a hard work­ing garbage col­lec­tor. To our sur­prise the old garbage col­lec­tor seems to have prob­lems to cope with the num­ber of objects over time. It spikes sev­eral times and in the end it even gets worse by spik­ing all over the place. That’s what we don’t want to see hap­pen­ing anywhere.

The con­clu­sion is that if you are run­ning some­thing that does more than print­ing out “Hello World” on Mono you surely want to take a look at the new mono-sgen garbage col­lec­tor. If you’re plan­ning to run the sones GraphDB on Mono we highly rec­om­mend to use mono-sgen.

9 comments zu “taking the new and shiny Mono Simple Generational Garbage Collector ( mono-sgen ) for a walk…”

write a new comment

*