How to make the MCR starting time fast
Asked Answered
B

2

5

I converted my matlab program into a .net assembly i.e a dll file. I have made a console C# application adding the dll file and called it from php. The MCR is called everytime the .exe is called. How can I make the MCR to initialize on the starting up of server and not closing everytime even if the exe is called after a certain time??And if there are any other methods to make this process fast please suggest.

Bespectacled answered 22/4, 2013 at 3:37 Comment(1)
The same suggestions you received on your previous question still apply (both compiled executables or .NET assemblies depend on the same MCR runtime). The idea is to start the MCR once and have it persist to handle all subsequent queries (as explained in Sam Roberts answer)Innominate
W
7

Not a whole lot you can do here directly. The MCR architecture has a high startup cost; it's not great for repeatedly-called short running programs.

You can make it faster by:

  • Making sure the MCR is installed locally on each machine that's running it
  • Pre-expanding the CTF archive for your compiled Matlab program
  • Deploying your compiled program locally on each machine that's running it
  • Buying solid state drives
  • Periodically doing a dummy run of your program in the background to make sure its files stay "warm" in the disk cache.

But these probably won't get you super fast; almost certainly not fast enough for reasonable page load times.

To really get it fast, you may need to change your program architecture to a client/server one, where you fire up a persistent server process that has your MCR code running in it, and it serves requests to your PHP clients. You'll need to do additional coding to make sure the requests are serviced in a "clean" context.

You could also load the MCR dll into your web server so it persists across the server lifetime. This would be a simpler setup, but you might be limited by the single-threaded Matlab session, and would have to deal with getting a clean starting point for each request.

The MathWorks solution to this is the new Matlab Production Server, which can load up compiled MCR code in to a worker pool and service client M-code requests from warmed-up preloaded Matlab worker instances. It addresses exactly this problem with MCR apps. The point of this or a DIY client/server approach is to "spin up" your MCR code in Matlab sessions before the client requests happen, so your clients never see the high MCR startup costs.

EDIT: There's a whole MathWorks guide on deploying MCR components to the web, the MATLAB Application Deployment Web Example Guide, that doesn't use just the Matlab Production Server. Looks like they mostly say to go client/server, but you can also load up your MCR component directly in the web server for low load levels.

Womanish answered 22/4, 2013 at 5:41 Comment(2)
actually it is a web application. So can we do anything on the server to make it fast? I will install MCR but apart from that?Bespectacled
The advice all applies to web applications, too; "each machine it's running on" refers to just the server(s) in this case. You could also change the architecture to load your dll file directly in to a persistent part of your web server and have php call it inside the server; though you'd be limited by the single-threaded nature of the Matlab session. Have a look at MathWorks' MATLAB Application Deployment Web Example Guide: mathworks.com/help/pdf_doc/compiler/example_guide.pdf.Womanish
V
0

Just as an addition to everything in answer above, may I suggest setting up a RAM drive, and setting MCR_CACHE_ROOT system variable to a directory on a RAM drive.

This will significantly improve further startup times.

Make sure your RAM drive is persistent during reboots, if anyone uses this scheme on a desktop.

Vernverna answered 2/4, 2020 at 10:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.