From: Chris Yeoh <yeohc@au1.ibm.com>

- fixes wild swings in memory usage related to usage of GetDrawStringSize()

  We've been seeing wild swings in memory usage and a large chunk of
  memory leak. From analysing this it's pretty clear that the mono
  garbage collector is rather buggy! When exercised heavily it looks
  like it frees more than its meant to resulting in crashes.

  GetDrawStringSize() measures the size in pixels of text. To do this
  memory for an image is allocated and used to call the GDI text
  measure functions.  Although no reference to the temporary memory
  for the measuring is kept, it takes quite a while for the mono
  garbage collector to clean up - so if lots calls to
  GetDrawStringSize() are made at once there can be a spike in memory
  usage. If the garbage collector is not fast enough then the GDI
  layer runs out of memory. It also looks like the garbage collector
  is not always reclaiming all of the memory.

  I've attached an OpenSim patch which works around the garbage collector
  issues. Instead of dynamically allocating memory for measuring
  text sizes, it serialises (on a per region basis) access to a single
  block of memory. The effect of this is to be nicer to the garbage
  collector as it has a lot less work to do, at the cost of some
  theoretical loss in performance (nothing noticeable with our tests
  which hit it pretty hard).

  OpenSim still does leak memory slowly, but it is a lot more stable
  with this patch. I suspect that either the garbage collector misses
  bits of freed memory or the GDI/cairo layer leaks a bit each time a
  texture is created. Thats going to be a lot harder to hunt down, but
  for reference if someone has OpenSim running on Windows it would be
  interesting to see if it has the same problem as it would tell us if
  its a mono/GDI problem or an OpenSim problem.
0.6.6-post-fixes
Dr Scofield 2009-06-03 12:39:44 +00:00
parent 25a0a56570
commit 074b66ddcf
1 changed files with 13 additions and 7 deletions

View File

@ -50,7 +50,8 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender
private string m_name = "VectorRenderModule";
private Scene m_scene;
private IDynamicTextureManager m_textureManager;
private Graphics m_graph;
public VectorRenderModule()
{
}
@ -96,14 +97,13 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender
public void GetDrawStringSize(string text, string fontName, int fontSize,
out double xSize, out double ySize)
{
Bitmap bitmap = new Bitmap(1024, 1024, PixelFormat.Format32bppArgb);
Graphics graph = Graphics.FromImage(bitmap);
Font myFont = new Font(fontName, fontSize);
SizeF stringSize = new SizeF();
stringSize = graph.MeasureString(text, myFont);
xSize = stringSize.Width;
ySize = stringSize.Height;
lock (m_graph) {
stringSize = m_graph.MeasureString(text, myFont);
xSize = stringSize.Width;
ySize = stringSize.Height;
}
}
@ -117,6 +117,12 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender
{
m_scene = scene;
}
if (m_graph == null)
{
Bitmap bitmap = new Bitmap(1024, 1024, PixelFormat.Format32bppArgb);
m_graph = Graphics.FromImage(bitmap);
}
}
public void PostInitialise()