How to make the MCR starting time fast

我与影子孤独终老i 提交于 2019-12-22 08:57:28

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/16139033/how-to-make-the-mcr-starting-time-fast

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!