| Contents | Index |
| On this page… |
|---|
The Server Administrator's Role in Deployment An Overview of Deployed Applications Installing the MATLAB Compiler Runtime (MCR) Loading the MATLAB Compiler Runtime (MCR) |
Server Administrator
|
|
|
|
In many organizations, integration developers do not handle actual production systems. Instead, a group of people that have access to these systems and manage various applications running on shared hardware take responsibility for this task.
System management requires ensuring that one set of applications does not affect another and also managing version conflicts that arise. Another concern of the server administrator is monitoring system up-time. The following sections discuss the nuances of the deployment products and what the server administrator role needs to do to ensure a successful deployment. It provides different methods of dealing with common issues that can affect stability and performance.
You can compare the relationship between compiled Java code and the JRE to the relationship between a compiled MATLAB program and the MCR. To execute Java code, you need a compatible version of the JRE on the system to execute it.
The deployment products, similarly, provide the compiled MATLAB application with a language-specific wrapper. The MCR provides the run-time infrastructure that runs deployed applications. It is made up of mostly native code.
When a deployed application integrates with a .NET or Java application, it resembles the figure "An Integrated Deployed Application."
An Integrated Deployed Application

In this figure, you can see how the MCR (a large native code base) exists within the outer process of the frameworks. This coexistence can cause issues, as illustrated later in this chapter.
Because the MCR provides the run-time infrastructure that runs deployed applications, it is a large application made up mostly of unmanaged code. It comprises an almost full copy of MATLAB, only distributable. It has no desktop and only executes encrypted code generated by the MATLAB Compiler and builders. For a deployed application to function against the MCR, you include references to specific directories on your Windows®, Linux®, or Mac OS® X path. For more information, see End User Installation with the MATLAB Compiler Runtime (MCR).
The MCR Installer ships with MATLAB. You obtain it from the MATLAB programmer who originally compiled the application. The version number of the MCR Installer is the same as the version number of MATLAB. The platform you install it on is the same as the platform on which MATLAB runs. The installer places the MATLAB libraries in a configurable location and, on Windows, automatically updates the system path.
You sometimes run a deployed component on a different platform than where it originated (especially for the Java target). To port across platforms, you need a version of the MATLAB installer for your target platform.
For both MATLAB Builder NE, and MATLAB Builder JA, a Helper Library ships with the MCR. This library contains information for communicating with the MCR. It also communicates with helper utilities and data types implemented by the wrapper code. Using these wrappers, you can convert your data to and from MATLAB data types.
Because deployed applications use the MCR at runtime, the MCR must be loaded and running. The MCR loads when a class in a deployed component is instantiated for the first time.
MCR loading can take anywhere from 10 seconds to over a minute (if the MCR resides on a network). To ensure a consistent user experience for Web applications, load the MCR at server start-up time, rather than upon first use, by instantiating a class as part of the server initialization.
In a J2EE server, you write a ContextListener class that contains code the server automatically runs when you install or remove the application.
Utilize the class by placing the following code in your web.xml file:
<listener> <listener-class>myContextListenerClass</listener-class> </listener>
Place this code in your class:
import javax.servlet.*;
public final class myContextListener
implements ServletContextListener
{
public void contextInitialized(ServletContextEvent event)
{
// This method is called when the application
// is first deployed in the server
//Instantiate the deployed component,
// this will trigger the MCR to be started
event.getServletContext().setAttribute
( "myComponent",
new myComponent.MyComponent());
}
public void contextDestroyed(ServletContextEvent event)
{
// This method is called when the application
// is shut down on the server
myComponent.MyComponent myComp =
event.getServletContext().
getAttribute("myComponent");
if(myComp != null)
{
// Dispose of the object when the
// server is shut down
// since it utilizes native resources
// that the garbage
// collector won't clean up.
myComp.dispose();
}
}
}
There are two methods to achieving scalability:
Calculation scaling involves increasing computer resources to scale and improve performance for a specific calculation. In MATLAB, the Parallel Computing Toolbox enables your MATLAB code to use features built into the MATLAB Language. These features tie into a cluster and enable your functions to run in parallel. Parallel processing can drastically speed up the execution of a function.
There are multiple strategies towards make your applications scalable—one is done by writing your MATLAB code to scale to a parallel computing algorithm. You may ultimately have calculation scaling as well as Session Scaling to optimize performance.
Session scaling involves enabling the maximum number of users while minimizing performance degradation.
Many session scaling issues arise because the MCR is single threaded. A single-threaded application prevents two users from doing work that involves the MCR at the same time. One user must wait for the other to finish before continuing. This wait can prove to be substantial if one user is performing a resource-intensive task while the other is attempting a quick calculation.
To workaround the situation, enable multiple MCRs to service requests as they arrive. Run several MCRs in separate processes; one process per MCR. Using this technique, you can create a separate server process that receives requests, runs the requests against one of the processes, and returns the result.
In one solution, servers reside in a third-party grid managed by a tool that spawns processes for each instance. Alternatively, you create your own pooling solution and manage these processes manually. For either approach, you accomplish the communication using either Java RMI or .NET Remoting because deployed components and data types can be serialized.
In most cases, MATLAB code executes quickly, and you do not need to do anything to get your desired level of performance. As a best practice, start with a single MCR. As your usage grows, add in a scaling layer as needed. Adding another layer involves minimal client changes.
Remote Scaling

In your default scenario, avoid using the MCR in the same process as the rest of your application. The MCR is a large complex native application running inside your applications process. If the MCR runs in the same process, you cannot ensure fault tolerance in the compiled application. To ensure that it does not affect the outer process, move it to its own process and pass the data back and forth.
Remoting provides the ideal solution, as discussed in Scaling Your Server Environment. Remoting allows you to start up a process whose only job is to start the MCR and run requests against it. Starting this process enables lightweight access from the client.
Both MATLAB Builder NE and MATLAB Builder JA have features that allow you to auto-convert MATLAB data types into Java or .NET data types. This auto-conversion frees you from running an MCR where the client process executes, yielding a robust more application.
Using Remoting to Achieve Fault Tolerance

![]() | Server Administrator Tasks | Hot Deployment | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |