mcneel / compute.rhino3d

REST geometry server based on RhinoCommon and headless Rhino
Other
284 stars 182 forks source link

Memory leak/issue #396

Open JosefJoubert opened 3 years ago

JosefJoubert commented 3 years ago

Hi

First of all, thanks for your swift response to my previous issue #394 .

Sorry to bring you more problems but here we are.

There seems to be a big memory leak in compute.geometry relating to the inputs. I use Python to run Grasshopper scripts on a local compute server. I used this code to test it:

import compute_rhino3d
import compute_rhino3d.Util
import compute_rhino3d.Grasshopper as gh
import os 
from tqdm import tqdm
file_directory = os.path.dirname(os.path.realpath(__file__))

GrasshopperScript_filepath = os.path.join(file_directory,"Grasshopper_Library/test.gh")

# Prepare for communication with RhinoCompute
rhino_URL = "http://localhost:8081/"
compute_rhino3d.Util.url = rhino_URL

Grasshopper_Inputs = {
    "InputString": ''.join(['a']*1000000),
    "InputNumber" : 5
}
variable_trees = []
# Prepare variables for Grasshopper
for variable_name in Grasshopper_Inputs:
    variable_value = Grasshopper_Inputs[variable_name]
    variable_tree = gh.DataTree(variable_name)
    variable_tree.Append([0],[variable_value])
    variable_trees.append(variable_tree)
for x in tqdm(range(1000)):
    compute_output = gh.EvaluateDefinition(GrasshopperScript_filepath,variable_trees)

It doesn't really do much besides just running a GH script over and over again. The test.gh script is just:

image

As you can see, nothing happening except getting and outputting variables.

After I run this I see:

image

Which is quite hefty! We like leaving our compute server up and running continuously, so this becomes a problem after a while. It seems the effect is directly related to the size of the inputs. In my Python example you can adjust the size of the inputs to see how it affects the memory. Small inputs have basically no effect, while large inputs can make it balloon rather quickly. So I'm assuming the problem is there.

Perhaps the inputs aren't being cleared? I prodded around in the source code to see if I can find an obvious mistake, but unfortunately I'm no C# expert and couldn't find anything.

Perhaps I'm doing something wrong on my side?

Let me know!

I know you've made some steps towards this issue in the past #61. I'm not sure if this is the same problem.

stealthlego commented 2 years ago

I am seeing a similar issue where I am importing a mesh and generating geometry around that. My files are quickly getting to 10s of GB of memory, which isn't super sustainable in the long term. Any progress on this since this initial issue was posted?

sanchez commented 1 year ago

I have been able to reproduce this as well, even if I reach the limit of what can be provided through the /grasshopper endpoint and get an error message saying the request is too large, I notice the memory still seems to leak by the approximate amount of what I uploaded.

Running this directly in powershell not through IIS.