MathWorksServiceHost issues (really slows down startup and then doesn't stop when matlab stops) in 2024a

With 2024a on Linux, when the matlab process starts, MathWorksServiceHost and MathWorksServiceHost-Monitor are started from the user's home directory, which REALLY slows down the startup when the home directory is mounted over the network. I've been able to mitigate the slowdown a bit by having $HOME/.MathWorks/ServiceHost get created a simlink to the local /tmp dir However...
MathWorksServiceHost and MathWorksServiceHost-Monitor don't stop when the matlab process stops. This is a problem on a multi-user system where, we then have a bunch of processes just hanging around for no reason.
This first issue is a problem, but not too major an issue, but the second would seem to me to be a bug.

Answers (4)

While we'd much prefer a switch that can be a default option (come on MathWorks!) in our cluster, we've found that instead of using /tmp, using a symbolic link to /dev/null to replace $HOME/.MathWorks works fine, like ln -s /dev/shm $HOME/.MathWorks
Caveat: we have a concurrent license server for our licensing. I'm not sure how that would work with other licensing methods.
Build that link in a matlab wrapper script to replace matlab, something like:
#!/bin/bash
if [[ ( ! -h $HOME/.MathWorks || ! $(readlink -f $HOME/.MathWorks) == "/dev/null" ) ]]; then
if [[ -e $HOME/.MathWorks ]]; then
rm -rf $HOME/.MathWorks
fi
ln -s /dev/null $HOME/.MathWorks
fi
echo "you may safely ignore 'mkdir: cannot create directory ‘/home/wcit/hughmac/.MathWorks’: Not a directory' message, below"
/usr/local/matlab/bin/matlab $@
Hope that's useful to others!

5 Comments

Linking to /dev/null is better than linking to a folder in /tmp the way I originally did it. I make $HOME/.MathWorks/ServiceHost be the link to /dev/null, rather than the whole .MathWorks directory, because for all I know .MathWorks may also be used for something useful. All I want (for now, anyway) is to disable the ServiceHost uselessness, which this does.
Additionally, I don't do it with a wrapper script; I have the environment module check/make the link when it loads.
Thanks!
Have any of you noticed any negative effects to disabling it in this manner?
Mathworks claims it is essential
They list "Licensing" which is important. We use a local network license. It seems to specifically refer to communicating with Mathworks web services. We don't use any web services so maybe it isnt important for us.
I'm also not sure if the .MathWorks folder is used for anything else.
So far, I haven't had any reports from any of my users that this negatively effects Matlab's performance in any way. I've read that page, too, and I can say for sure that linking $HOME/.MathWorks/ServiceHost to /dev/null has NOT affected using the license server. I, too, am not sure what else .MathWorks is/may be used for, which is why I set up the link the way I do (see my previous post).
Ditto what Mike said: no negative effects, and plenty (many 10s of thousands) of Matlab jobs completed since then. Huzzah.

Sign in to comment.

Hi everyone.
We face the very same problem in our shared linux servers.
Having hundreds of users we cannot afford to have thousands of MathWorksServiceHost process spwaned all around the cluster.
Is there an official solution that i) speedup the Matlab startup, ii) does not require symlink to /tmp directory, and iii) avoids the MathWorksServiceHost process to remain in a running status after the Matlab is closed?

1 Comment

@Andrea Luciani So far, no. Running it using the contain script is possible for some people, although that didn't work for me.

Sign in to comment.

Hello Mike
I understand that you are facing issues with ‘MathWorksServiceHost’ where it slows down the MATLAB startup and you see that the ‘MathWorksServiceHost - Monitor’ don’t stop when the MATLAB process stops which leaves few processes not terminated.
It is recommended to uninstall and reinstall ‘MathWorksServiceHost’ when such issues are faced.
Please follow the steps mentioned in the following MATLAB Answer to do the same.
I hope that the above information is helpful.
Thanks,
Chaitanya

4 Comments

I appreciate your response after so long a time.
Is there anyway to just disable the service? We will never use MATLAB Drive, and if that is what MathWorksServiceHost implements, then it is useless to us, anyway.
@Mike VanHorn Thanks for posting this issue, we are facing the same thing on a new linux compute cluster. Did reinstalling MathWorksServiceHost help in any way?
No, because it doesn't address the problem. The "problems" we've identified in this thread are by design, so re-installing would be the solution to the software not working in this way (which is the way we don't want them to work).

Sign in to comment.

I just wrote contain to combat this very problem--it can prevent those daemons from persisting after Matlab exits. We now put this script (but NOT the original matlab) in PATH:
#!/bin/bash
# Symlink their bloat directory to /tmp
if [[ -d ~/.MathWorks && ! -h ~/.MathWorks ]]; then
mv ~/.MathWorks ~/.MathWorksOld
echo "WARNING: moved ~/.MathWorks to ~/.MathWorksOld; unless you need it, remove ~/.MathWorksOld."
fi
test -h ~/.MathWorks || ln -s /tmp ~/.MathWorks
# Launch matlab, contained so the daemons can't escape
module load apptainer contain &>/dev/null
contain /apps/matlab/r2024a/bin/matlab "$@"

1 Comment

Michael Greenburg,
That's a pretty cool script. I may use that for Cadence Virtuoso, too, as it has started doing to the same thing as Matlab in regards to superfluous daemons.

Sign in to comment.

Categories

Products

Release

R2024a

Asked:

on 19 Apr 2024

Commented:

on 24 Mar 2025

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!