Archive

Posts Tagged ‘Server’

Gotcha: use server-side comment, not HTML comment in ASP.net

I try to remember to use <%– and –%> instead of <!– and –> for comments in server-side web pages, to avoid having implementation details (for security reasons that is) in the output HTML and to keep the download size smaller / have the pages load faster.

What came to me though the other day while making some metadata editing pages for ClipFlair Gallery, was that if you don’t use server-side comments and use classic HTML comments in server-side pages, the code inside the HTML comments is executed at the server side and its output is placed in HTML comments at the web page the client browser downloads.

So this can potentially lead to a very big download and to increased time to generate the page at the sever-side if you accidentally comment out some code block you were using for testing and don’t use server-side comments, but use HTML comments instead to comment it out.

What got me into suspission was the syntax highlighting of Visual Studio 2010. Note below that <%@ Register isn’t highlighted green (as it would be in a server-side comment).

<%@ Page Language="C#" 
         AutoEventWireup="true"
         Title="ClipFlair Activity Gallery"
%>

<!-- THIS IS A BAD USE OF HTML COMMENT MARKER, USE SERVER-SIDE COMMENT INSTEAD

<%@ Register Assembly="CustomXml" Namespace="PAB.WebControls" TagPrefix="cc2" %>

<cc2:CustomXml 
  DocumentUrl="http://gallery.clipflair.net/activity/all.xml"
  XslUrl="http://gallery.clipflair.net/activity/activity.xsl"
  runat="server"
  />

-->

...

Probably JavaEE’s JSP behaves similarly (uses the same symbols for server-side comments), but haven’t tested it.

Advertisements
Categories: Posts Tags: , , , , ,

YouTube (Google) 502 error page

image

Note the page title says “Error 502 (Server Error)!!1”

Categories: Posts Tags: , , , , ,

Launching MATLAB with no UI (headless) for remote automation

I’m sharing here an answer I just gave at:

http://stackoverflow.com/questions/3100251/can-i-run-matlab-on-windows-with-ui-just-that-the-code-runs-on-remote-server/7507515#7507515

for archiving, since this may interest fellow Roboticists

Launching MATLAB on a server without the GUI is covered thoroughly at
http://blogs.mathworks.com/desktop/2010/02/22/launching-matlab-without-the-desktop/
you should also read the user comments/discussion there

e.g. you can use

start matlab -nosplash -nodesktop –nojvm –noFigureWindows -minimize -r
"testcommand,quit"

 

The –noFigureWindows parameter is mentioned at
http://www.mathworks.com/help/techdoc/ref/matlabwindows.html
where it doesn’t mention –nodesktop (only the UNIX doc mentions it for X-Windows), however it seems you have to use it on Windows too, else you see the MATLAB code editor window too popup.

 

I’m not sure the –nojvm works at all on Windows version of MATLAB, it’s not mentioned in the official documentation URL mentioned above and also Process Monitor tool from Microsoft SysInternals shows that MATLAB still loads it’s internal Java VM’s files even with that command-line parameter provided.

If not using Java is too restrictive for your needs:

Regarding -nodesktop vs. -nojvm, there is a third
(undocumented/unsupported) option: ‘-noawt’. -noawt loads Java (thus
enabling Java I/O, data structures etc.) and just prevents Java GUI

 

Also note that when launching MATLAB from a WCF service, even if you set an AppPool to run the service under a custom account (say MATLABUSER) and even if you set the Matlab current directory / search path for that user (Matlab keeps them separately for each Windows user account), it keeps on ignoring them. Thus you are forced to use “-sd” deprectated command-line parameter of Matlab (mentioned at the official doc URL I sited above) to set the startup path of Matlab. In that folder you can have a “startup.m” file where you use ADDPATH command of Matlab to temprorarily update the Matlab startup path for the running Matlab process.

ADDPATH Add directory to search path.
    ADDPATH DIRNAME prepends the specified directory to the current
    matlabpath.  Surround the DIRNAME in quotes if the name contains a
    space.  If DIRNAME is a set of multiple directories separated by path
    separators, then each of the specified directories will be added.
 
    ADDPATH DIR1 DIR2 DIR3 …  prepends all the specified directories to
    the path.

Unfortunately the “-sd” command-line parameter is deprecated, which means it could be removed in the future, but the Matlab online documentation fails to list alternatives, just says “For information about alternatives, see .” and nothing more there:

matlab -sd "startdir" specifies the startup directory for MATLAB (the current directory in MATLAB after startup). The -sd option has been deprecated. For information about alternatives, see .

 

BTW, instead of launching MATLAB via Windows shell command you could launch as a COM automation server:

http://www.mathworks.com/help/techdoc/matlab_external/brd0v3w.html

or via existing C API for launching MATLAB:

http://www.mathworks.com/help/techdoc/matlab_external/f29148.html

 

If you use this often (e.g. from a web service), it is best that you keep an instance of MATLAB in memory all the time (since Windows apps for example share code and have separate data this can spare much time by avoiding the reloading of MATLAB code into memory at every script run). That instance could be headless too (with no UI) using this command at server boot (e.g. by adding an entry at HKLM/Software/Microsoft/Windows/CurrentVersion/Run in the Windows registry using "regedit.exe"):

start matlab -nosplash -nodesktop –nojvm –noFigureWindows -minimize

%d bloggers like this: