mathworks / matlab-proxy

Python® package enables you to open a MATLAB® desktop in a web browser tab.
Other
48 stars 23 forks source link

Close MATLABProxyApp automatically after Matlab has been stopped via browser #36

Closed swdn133 closed 1 month ago

swdn133 commented 2 months ago

Details of the feature

Usecase is the following: I have a docker container running matlab and matlab-proxy as described. I access matlab via browser and everything works fine. After I am finished working, I select the "Stop Matlab" option in the browser and matlab stops.

My issue: the MATLABProxyApp process is still running. So my container is kept alive and continues blocking resources.

It would be great to have some kind of Timeout that autmatically stops the proxy app when no matlab is running.

I know that the env variable MWI_SHUTDOWN_ON_IDLE_TIMEOUT exists. But this is not the behaviour i would like to see. When setting this variable, the container will also be shutdown when matlab is still active but idle. I think it would be great to have the option to let matlab be alive when idle but shutdown the proxy-app when no matlab is running at all.

prabhakk-mw commented 2 months ago

Thank you @swdn133 !

Would a button along side the "Stop MATLAB" option that terminates both MATLAB and the MATLAB-PROXY-APP processes serve your needs?

swdn133 commented 2 months ago

Hi @prabhakk-mw

Yes, that would be a perfect solution for my use case :)

prabhakk-mw commented 2 months ago

We are on it!

swdn133 commented 2 months ago

Awesome, thanks a lot!

prabhakk-mw commented 1 month ago

@swdn133

A "Shut Down" button has been added to v0.23.1 of matlab-proxy

image

Could you please confirm that updating to this version shows the button, and that it behaves as expected in your environment?

Thank you!

swdn133 commented 1 month ago

That looks amazing. Thx for your work. I will check it out an come back to you asap.

prabhakk-mw commented 1 month ago

Thank you @swdn133 ! Please do let us know if this feature worked as expected on your end.

prabhakk-mw commented 1 month ago

Hi @swdn133

Some of us were discussing this issue, and were hoping to get some more information related to this statement:

My issue: the MATLABProxyApp process is still running. So my container is kept alive and continues blocking resources.

When you say kept alive, I assumed you had some infrastructure that automatically closes containers when there are no user processes running.

Could you tell us more about how to configure such an environment?

swdn133 commented 1 month ago

Hi @prabhakk-mw,

first of all: I was able to try out the new release and can now confirm that your feature works as expected and helps a lot with my workflow. Again: thx for your work.

swdn133 commented 1 month ago

Sure, I can elaborate a bit on my desired workflow @prabhakk-mw

I use a docker container that starts Matlab proxy app.

I start the container somewhat like that: docker run --rm --gpus all -v /mount:/stuff my-matlab-docker-image start_matlab_proxy_app.sh

This starts the container and with the start launches the Matlab proxy app. Since I started the container with the --rm flag, it is running as long as the proxy app runs and gets automatically deleted when the docker app exits.

So the first major use case is the following: I have a powerful remote server with a couple of GPUs to do the heavy compute stuff. I ssh on that remote server, start the container and thereby the Matlab proxy. I now can connect via browser to Matlab running on the server and do my stuff remotely on that server. When I am finished, I use the new "shutdown" functionality in the browser app and the container on the server exits, gets cleaned up and the server is again in a clean state so that some other colleague can use it.

Second (and more important) use case: I would like to deploy the container on a Kubernetes cluster. Just as described above. As long as the container is running, it has the specified amount of resources assigned to it (moste importantly: GPUs). Now when I am finished with my work and close Matlab in the browser I need the container to exit so that the assigned resources are freed on the Kubernetes cluster. Before having the new feature, the container keeps running (because the proxy app is still running) and therefore keeps blocking (GPU) resources.

I hope you understand the explanation and my thoughts behind it. If I can provide any further information, feel free to reach out.

prabhakk-mw commented 1 month ago

This clears up everything! Thank you for the quick and detailed response.

The team will be happy to hear that the feature works as expected.