itszootime/matlab-connector — pull request #7 by lushc (2013-11-13 17:10:10+00:00)
Title: MATLAB eventually hangs when evaluating requests

Hi Richard,

I very recently encountered a strange issue when using the matlab-connector on cs-lightning. The pooled MATLAB instances would eventually "timeout" and become unavailable. If enough requests were made all the instances would be tied up and the matlab-connector server would have to be rebooted.

Take this example request:

```json
{
"type":"ValidationRequest",
"observed":[1.0,3.0,3.0,1.0,2.0,4.0,6.0,8.0,9.0,10.0,6.0,3.0,4.0],
"predicted":[
{"mean":2,"variance":1},{"mean":4,"variance":2},{"mean":2,"variance":1},{"mean":1,"variance":1},
{"mean":2,"variance":2},{"mean":5,"variance":1},{"mean":4,"variance":1},{"mean":7,"variance":1},
{"mean":9,"variance":2},{"mean":9,"variance":2},{"mean":7,"variance":1},{"mean":3,"variance":1},
{"mean":5,"variance":1}
]
}
```
I'd be able to run this request 6 times before the 7th request hanged:

```
2013-11-12 15:19:57,205 [Thread-11] INFO org.uncertweb.matlab.server.MLServerThread - Received request for function 'validate_predictions'.
2013-11-12 15:19:57,237 [Thread-11] INFO org.uncertweb.matlab.instance.MLInstance - Evaluating function validate_predictions...
2013-11-12 15:20:17,926 [Thread-11] INFO org.uncertweb.matlab.instance.MLInstance - Evaluation complete, parsing results...
```

A new request meant a new instance would then be used from the pool until eventually all instances were stuck on parsing results. I added some additional logging and it'd just hang at the same value for each request, i.e. when evaluating "result1s=result1.meanqq". For the stuff we're doing for [GeoViQua](http://www.geoviqua.org) I'm sending 4000ish values and this would cause the 1st request to fail at the same point of execution: whenever the proxy was evaluating the results set.

I couldn't reproduce this issue locally on my Windows machine but when MATLAB is [set to hidden](http://matlabcontrol.googlecode.com/svn/javadocs/doc/matlabcontrol/MatlabProxyFactoryOptions.Builder.html#setHidden(boolean\)) the -nosplash and -nodesktop switches are used which seems to fix the issue on cs-lightning (I tested 500 consecutive requests).

Originally I had changed the matlabcontrol dependency from 4.0.0 to 4.1.0 to see if that fixed the issue. I figured it could be left in as it seems to be a worthwhile upgrade and is fully compatible with 4.0.0 ([source](http://code.google.com/p/matlabcontrol/wiki/VersionHistory))

Thanks for your time!

Chris L