Remote Modules¶
Remote modules¶
The remote modules concept of MeVisLab provides inter-process communication. It is based on a remote messaging protocol and allows for the synchronization of MeVisLab fields between different processes. .. note:: To be able to use this functionality, a license that allows to develop remote applications is needed.
A remote module can be created in the MeVisLab IDE by clicking on Run In Separate Process in the module context menu. MeVisLab replaces the target module by a proxy module, which mirrors the fields of the target module in a new MeVisLab process. Hence the remote module can be used in the network as if it were the target module. Existing connections of the target module are retained.
A remote module can also be created by scripting with the call to ctx.addRemoteModule().
When the remote module is created, MeVisLab launches a worker process in the background, which creates the target module. MeVisLab and the worker process communicate over a socket connection using remote messages. Parameter field values are then synchronized in both directions between MeVisLab and the worker process. Image fields are only supported as output fields, not input fields (see Restrictions). Base fields can be both, input and output fields, but they require a special base handler for each Base type.
It is possible to have more than one remote module in an application, but each module gets its own worker process. The worker processes are managed by an embedded worker manager in the main MeVisLab process. Worker processes are terminated when the remote module is deleted or MeVisLab is closed.
Restrictions¶
Remote modules try to hide their remote character as good as possible, but this is only possible to a certain amount. The following restrictions exist:
Image inputs are not supported. (Image fields require synchronous calls, and deadlocks could occur if an remote module had both Image inputs and outputs.) It is anyway not worth to load an image in the main process and then move the image data to the worker process. Load it directly in the worker process instead; you might need to create a macro module for this.
Image output fields do not support image extension information apart from the DICOM tree.
Inventor nodes and fields do not work.
Scripting only works on field level. Scripting that is called from the GUI or tries to access GUI elements will generally not work, since scripting is done in the remote process and has no access to the GUI on the client.
Use an
ItemModelViewinstead of aListViewif you need to display lists or tables in your GUI.Module fields will not update immediately after some other field was changed, since changes are transmitted asynchronously.
MeVisLab WorkerService¶
The worker manager is also available as a standalone executable: MeVisLabWorkerService. It can actually run multiple worker managers (worker servers) with different configurations. A worker server will create a worker process for each incoming connection. Two different connection types are supported: MLABBinary and WebSocket. Connections of the type WebSocket are used for web applications (see the MeVisLab Web Toolkit Reference reference). MLABBinary connections are used for any other client that supports the remote messages protocol over a TCP socket (another MeVisLab instance, for example). The worker service can operate in two different modes concerning the client connection: the Direct Mode and the Full Proxy Mode.
Besides managing worker processes, the worker service features a simple built-in web server. It is enabled by specifying the <httpServerPort> setting in the configuration file. Its main intent is to aid development, there is no focus on security and performance. Keep this in mind when you think about using the built-in web server in a productive environment.
The worker service also provides a simple alive check. It is enabled by specifying the <aliceCheckPort> setting in the configuration file. If enabled, then the worker service accepts (and then immediately closes) TCP connections on the specified port. This can be used, e.g. by a load balancer, to check whether the worker service is alive.
There is also a WorkerService module in MeVisLab. It provides a GUI to edit the worker service configuration and it can control the worker service executable.
Command-line Usage¶
MeVisLabWorkerService(.exe) [-settings-file <filepath>] [-install] [-uninstall] [-start] [-stop] [-exec]
-settings-file <filepath> instructs the worker service to read this configuration file instead of the default one
-install/-uninstall installs/uninstalls the worker service executable service
-start/-stop starts/stops the worker services as service, requires that it is installed as a service
-exec executes the worker service as a normal process
The worker service executable exists in the bin directory of the MeVisLab/IDE package. Although the worker service is implemented as a QtService, it should typically be started as a normal process on Windows versions from Vista/7 onwards. This is because services on Windows cannot access the graphics hardware, so that OpenGL will fall back to the software implementation. Remote rendering will fail then, because required functionality is missing in this implementation. This also means, that the worker service should not be started as a scheduled task, which is also a Windows service. If no configuration file is specified with the -settings-file-option, then the configuration file is searched for in the default location, which depends
on the target platform:
Windows: C:\ProgramData\MeVis\WorkerService.xml
Linux: $(HOME)/.local/share/MeVis/WorkerService.xml
Direct Mode¶
The direct mode is enabled by default, or explicitly via setting <proxyMode> to “NoProxy” (legacy value “false”).
The direct mode supports serving one application per worker server, which means each application uses a different module port and HTTP port. For each connection request on the module port a worker process is launched. The connection is transferred to the worker process after it has started. This results in a direct connection between the client and the worker process. This mode supports prestarting of workers.
Single Application Proxy Mode¶
The single application proxy mode is enabled by setting <proxyMode> to “SingleAppProxy”.
The single application proxy mode supports serving one application per worker server, which means each application uses a different module port and HTTP port. For each connection request on the module port a worker process is launched. This results in a proxied connection between the client and the worker process. This mode supports prestarting of workers and authentication using <authenticationRequestUrl> (see Full Proxy Mode)
Full Proxy Mode¶
To enable the full proxy mode, you must set <proxyMode> to “FullProxy” (legacy value “true”). Other mandatory settings in the configuration files are: <applicationConfigDir>, <httpServerPort>, and <modulePort>. Other settings can be configured in the application configuration file, the worker service configuration settings will be fallback values, if an application configuration does not provide them.
The full proxy mode allows for serving multiple applications per worker server. This allows them to share the same module port and HTTP port. The worker service multiplexes all connections instead of transferring them to the worker processes as in direct mode. It looks at the first request to determine which application configuration to use and then forwards all communication with the worker processes via a local socket connection, hence the worker service is acting as a proxy server.
The applications themselves are configured through separate configuration files, which must exist in <applicationConfigDir> (see section XML Configuration File). The names of the configuration files are derived from the application names.
The application name and an optional authentication token are transmitted to the worker service. The transmission method depends on the connection type.
If it is MLABBinary, then both values must be passed by MLABRemote::MessageSelectApplication.
If the connection type is WebSocket, then the values are provided as part of the web socket URL:
ws(s)://hostname:port/someMagicString/applicationName/authenticationToken. The MeVisLab Web Toolkit handles this already. Both values are configured through the connection settings.
The authentication token can be used in conjunction with the <authenticationRequestUrl> setting to prevent DOS attacks based on launching worker processes (see also Application URLs).
For HTTP requests, the target application is addressed by the application name in the URL, which would look like this: http(s)://hostname:httpServerPort/Applications/applicationName/PackageGroup/Package/… .
XML Configuration File¶
All path name settings may be relative to the directory of the configuration file itself. An example configuration file can be found in the repository under MeVisLab/IDE/Configuration/Installers/WorkerService/config.
<workerService>
// Specifies the directory for the log files of all worker servers and worker processes.
<logDirectory> /path/to/logdirectory </logDirectory>
// A worker server configuration.
<workerServer>
// The port on which the worker server listens for alive check connections.
<aliveCheckPort> 0 </aliveCheckPort>
// Specifies the path to the directory with the application-specific configuration files (proxy mode only).
// The configuration entries are the same as described above. This is optional. By default,
// the application directory next to the configuration file is used.
<applicationsConfigDir> /path/to/applications </applicationsConfigDir>
// See section "Application URLs" below.
<applicationStartedUrl> URL </applicationStartedUrl>
<applicationStoppedUrl> URL </applicationStoppedUrl>
<authenticationRequestUrl> URL </authenticationRequestUrl>
<authenticationRequestUrlHeader header="Some-Header" value="$(authenticationToken)" />
// If infoUrlsSubnet is specified, specify additional username and password
// (separated by colon) to access detailed connection information (including
// IP address in proxy mode). Example: myusername:mypassword
<connectionInfoAuthorization> </connectionInfoAuthorization>
// If controlUrlsSubnet is specified, specify additional username and password
// (separated by colon) to access the control interface. Example: myusername:mypassword
<connectionControlAuthorization> </connectionControlAuthorization>
// Specifies the connection type for the module port, either "WebSocket" or "MLABBinary".
<connectionType> WebSocket </connectionType>
// If set to a sub-net mask, allow to control the WorkerService through URLs from the given
// IP range. E.g., pre-start workers through the embedded http server
// under http(s)://serverhost:httpPort/Control/prestartWorker?application=myapplication
// (only give the application parameter for full proxy connections).
//
// You can also terminate workers through this url:
// http(s)://serverhost:httpPort/Control/disconnect?workerLogId=<number>
// The number is the one returned by the connections Info interface (see <infoUrlsSubnet>).
//
// Lastly you can shut down the whole WorkerService through
// http(s)://serverhost:httpPort/Control/shutdown
//
// Example for allowed values: 192.168.5.1/24 or just 192.168.5
<controlUrlsSubnet> </controlUrlsSubnet>
// If set to true, then it implies writeMeVisLabLogFiles and an initial worker process is created,
// so that a debugger can be attached to it.
// Authentication tokens are not filtered from the log in this mode!
<debugMode> true </debugMode>
// When the WorkerService acts as an HTTP server and this option is on, every request
// for which no file was found will be routed to the index.html file in the directory
// given by the webContentDirectory tag.
<enableRouting> true </enableRouting>
// Defines environment variables, for details see section "Environment Variables" below.
<environment> ... </environment>
// The arguments to use with MeVisLab - if not given, then the default is "-quick -noide".
// You can use quotes for arguments that may possibly contain spaces.
<executableArguments> arg1 ... </executableArguments>
// Executable path for the worker processes (e.g.MeVisLab(App).exe).
//
// Note that if you don't execute the worker directly, in proxy mode you have to add
// the command line argument "-workerpid" to the MeVisLab call, together with the
// process id of the tool that was specified here, since that is used to connect the
// worker with the incoming client connection.
<executablePath> /path/to/executable </executablePath>
// Specifies additional file types that may be served by the built-in http server.
<extraFileTypesToServe>
<fileType mimeType="video/mpeg" extensions="mpeg;mpg;mpe" />
<fileType mimeType="..." extensions="..." />
</extraFileTypesToServe>
// If set to true, then the stdout and stderr of worker processes are forwarded to the stdout and
// stderr of the worker service. (Note: MeVisLab will not print any output unless the "-console"
// commandline argument is given.)
<forwardWorkerOutputToStdoutAndStderr> false </forwardWorkerOutputToStdoutAndStderr>
// Set the number of graphics cards available - new MeVisLab instances will be assigned to graphics cards
// in a round-robin scheme. This currently only works for NVidia cards.
<gpuCount> 2 </gpuCount>
// The port under which to access (by http protocol) files from the MeVisLab installation.
// The files from the installation will be accessible from these URLs:
// - http(s)://hostname:httpServerPort/Packages/PackageGroup/Package/...
// - http(s)://hostname:httpServerPort/Applications/applicationName/PackageGroup/Package/... (proxy mode only)
// By default, only files ending on html, js, css, jpg, tif, gif or png will be served. Serving other
// file types configurable, see <extraFileTypesToServe> above.
// A special URL is http(s)://hostname:httpServerPort/Settings/webSocketPort. It will return a file
// containing only the port number of the WebSocket port. This is used by the MeVisLab Web Toolkit to
// automatically query the port for the WebSocket connection.
<httpServerPort> 8080 </httpServerPort>
// This parameter is true by default, but can be set to false, if you, e.g.,
// only want to use the control interface
<serveApplicationFiles> true </serveApplicationFiles>
// If set to "true", then ignore the user's preferences file in MeVisLab.
<ignorePrefs> true </ignorePrefs>
// If set to a sub-net mask, provide run-time information about current connections
// through the embedded http server under http(s)://serverhost:httpPort/Info/<sub-path> .
//
// <sub-path> can be:
// clientIPAddress: Returns the apparent IP address of the web client
// general: Some general information about the worker service as JSON
// connections: List of all running workers, with connected IP addresses (if connected) as JSON
// connections.html: Same as HTML page
//
// Example for allowed values: 192.168.5.1/24 or just 192.168.5
<infoUrlsSubnet> </infoUrlsSubnet>
// The log file name for this worker server, if not given, then it will be worker_$(portNumber)_$(currentDate).log
// A new file will be written per day by appending the current date. maxLogFileCount will remove the oldest log files when
// the log file for a new day is started. You can place a @date@ placeholder somewhere in the string to choose where the current date
// is added.
<logFileName> workerserver.log </logFileName>
// The maximum size (in bytes) for the daily workerservice log file - if 0 or not given, then the log files are not truncated.
// If the limit is reached, the log file is halfed in size by removing lines from the start of the file.
<maxLogFileSize> 10000000 </maxLogFileSize>
// The maximum number of worker service log files, if not given there is no limit to the number of worker service log files
<maxLogFileCount> 90 </maxLogFileSize>
// Restricts the number of connections that can be active for a worker server. When this number is reached,
// any new connection request is rejected.
<maxNumberConnections> 10 </maxNumberConnections>
// When no connection limit is given with maxNumberConnections, we can at least
// restrict the number of connections that are pending (i.e., waiting for a
// worker process to connect) with this entry. All other connections are rejected
// while this limit is reached.
<maxNumberPendingConnectionRequests> 5 </maxNumberPendingConnectionRequests>
// The port on which the worker server listens for connections for worker requests.
<modulePort> 4114 </modulePort>
// If set to true, then only connections from the local address (same host) will be accepted.
<onlyAcceptLocalConnections> false </onlyAcceptLocalConnections>
// Sets the license key to use for the MeVisLab worker process. Usually this will be
// a floating license key, and if given, the WorkerService will contact the license server
// to determine if a license lease is still available for this license key *before* starting
// a worker.
//
// If you want to skip this step, you can instead specify the -licensekey command line option
// in the executableArguments element to pass the license key directly to the worker process.
<overrideLicenseKey> XXXXX-XXXXX-XXXXX-XXXXX-XXXXX </overrideLicenseKey>
// Sets the file path to the MeVisLab license file to use.
<overrideLicensePath> /path/to/license/file </overrideLicensePath>
// Sets the path to a preferences file for MeVisLab.
<preferencesPath> /path/to/prefsfile </preferencesPath>
// Set the time after which an unused worker process is killed (in seconds).
// By default it is 0, which means it is disabled (e.g. for debugging).
<processDecayTimeout> 30 </processDecayTimeout>
// Selects the proxy mode. See section "Proxy Mode" above, default is "NoProxy"
<proxyMode> [FullProxy|SingleAppProxy|NoProxy] </proxyMode>
// Sets how many workers (MeVisLab instances) are pre-started. This is only supported in
// proxyMode != FullProxy. Typically you would also add -workerPrestartModule YourModuleName to
// the executableArguments, so that the MeVisLab instance has a pre-created module as well.
<prestartWorkers>2</prestartWorkers>
// Sets the time in ms that is waited after a client connects to a worker
// before a new worker is pre-started (if required).
<prestartDelayInMS>2000</prestartDelayInMS>
// The path to a config file in XML syntax describing a SSL certicate
// and a private key to use for connection encryption. If given, both HTTP and
// MeVisLab accesses will be encrypted, see section "SSL Configuration File"
// below for details.
<sslConfigFile> /path/to/ssl/configuration/file </sslConfigFile>
// Sets the path from which to serve HTTP requests. This can be used to hide
// the package structure from the web client. The worker service maps these URLs
// to the given path.
// http(s)://hostname:port/Packages/
// http(s)://hostname:port/Applications/applicationName/ (proxy mode only)
<webContentDirectory> /path/to/webcontent </webContentDirectory>
// If set to true, then a log file is created for each worker process.
// NOTE: the maxLogFileCount and maxLogFileSize do not apply to these MeVisLab worker log files, they are only
// used for the workerservice logs.
<writeMeVisLabLogFiles> true </writeMeVisLabLogFiles>
</workerServer>
</workerService>
In the text content of any of those tags, any environment variable can be used with the syntax $(ENV_VAR).
I.e., the MeVisLab executable can be set with <executablePath>$(MLAB_ROOT)/MeVisLab/IDE/bin/MeVisLab.exe</executablePath>.
Environment Variables¶
These environment variables have a special meaning, but any other environment variable may also be given and will overwrite existing ones.
<environment>
// Enables additional logging related to remote rendering.
<MLAB_DEBUG_REMOTE_RENDERING_PERFORMANCE> true </MLAB_DEBUG_REMOTE_RENDERING_PERFORMANCE>
// This setting will disable sending server log messages (e.g. MeVisLab logging) to the web client. This is optional.
<MLAB_DISABLE_REMOTE_LOG_MESSAGES> true </MLAB_DISABLE_REMOTE_LOG_MESSAGES>
// These package variables must be set to the correct path when the preferences file adds packages with necessary http resources
// that are not contained under MLAB_ROOT, because the worker service serves these files, but does not read the preferences file.
<MLAB_PackageGroup_PackageName> /path/to/package </MLAB_PackageGroup_PackageName>
// Sets the timeout that closes the connection when no messages have been received
// for this many seconds. An automatic keep-alive message is sent every 5 seconds.
// Set this to 0 to disable this (e.g. for debugging). This is optional.
<MLAB_REMOTE_BINARY_MESSAGE_TIMEOUT> 30 </MLAB_REMOTE_BINARY_MESSAGE_TIMEOUT>
// This will terminate the worker process when no heartbeat was received from the main
// thread of the worker for this time in seconds. The heartbeat is sent every 5 seconds. This is optional.
<MLAB_REMOTE_HEARTBEAT_TIMEOUT> 30 </MLAB_REMOTE_HEARTBEAT_TIMEOUT>
// As MLAB_REMOTE_BINARY_MESSAGE_TIMEOUT, but for WebSocket connections (e.g. the web client). As the web client usually does not
// send keep-alive messages, this can be used to disconnect on inactivity of the client. This is optional.
<MLAB_REMOTE_WEBSOCKET_MESSAGE_TIMEOUT> 30 </MLAB_REMOTE_WEBSOCKET_MESSAGE_TIMEOUT>
// This path must point to the directory containing the packages, aka MLAB_ROOT.
<MLAB_ROOT> /path/to/packages </MLAB_ROOT>
// Initially this is the content of the path variable when the configuration is added/updated from the WorkerService module.
<PATH> ... </PATH>
</environment>
Application URLs¶
These URLs are optional and are only used in proxy mode. The worker service will use them as a notification mechanism. It can inform a web application that wants to be informed if a worker was started or stopped. And it also uses the authenticationRequestUrl to ask the web application if launching a worker process is permitted. Two variables can be used in the URLs:
$(applicationName)
$(authenticationToken)
// The given URL will be requested whenever an application has been started, for example
// https://anyurl/appStarted.html?app=$(applicationName)&auth=$(authenticationToken).
<applicationStartedUrl> URL </applicationStartedUrl>
// The given URL will be requested whenever an application has stopped, for example
// https://anyurl/appStopped.html?app=$(applicationName)&auth=$(authenticationToken).
<applicationStoppedUrl> URL </applicationStoppedUrl>
// The given URL will be requested to check for authentication before a worker is launched.
// A HTTP response of 200 indicates that the request is authenticated and the worker service
// will launch a worker process. Any other response will prevent that.
// An example URL is https://anyurl/authRequest.html?app=$(applicationName)&auth=$(authenticationToken).
<authenticationRequestUrl> URL </authenticationRequestUrl>
// Some systems require the auth token as a header value, this can be passed with authenticationRequestUrlHeader:
<authenticationRequestUrlHeader header="Some-Header" value="$(authenticationToken)" />
Application Configuration File¶
The application configuration file supports a subset of the settings from the worker service configuration file. If a setting is not specified, it is looked up in the worker service configuration. The appliclation configuration filename must contain the application name that is known by the worker service, and it must exist in the <applicationConfigDir>. See XML Configuration File for the description of these settings.
<application>
<enableRouting> true </enableRouting>
<environment> ... </environment>
<executablePath> /path/to/executable </executablePath>
<executableArguments> -quick -appname appname </executableArguments>
<extraFileTypesToServe> ... </extraFileTypesToServe>
<ignorePrefs> true </ignorePrefs>
<overrideLicensePath> /path/to/license </overrideLicensePath>
<processDecayTimeout> 30 </processDecayTimeout>
<webContentDirectory> /path/to/webcontent </webContentDirectory>
</application>
SSL Configuration File¶
<ssl>
// Relative or absolute file path to the file that contains the private key, algorithm may be "rsa" or "dsa",
// and encoding may be "pem" or "der".
// passphrase is only needed if the private key requires a passphrase (it should contain only ascii characters).
<privateKey algorithm='Rsa' encoding='Pem' passphrase='passphrase'> /path/to/privatekeyfile </privateKey>
// Relative or absolute file path to the certificate, encoding may be "pem" or "der".
<certificate encoding='Pem'> /path/to/certificate </certificate>
// Relative or absolute file path an intermediate CA certificate, encoding may be "pem" or "der".
// Multiple intermediate certificates can be specified to specify the complete certificate chain.
<intermediateCertificate encoding='Pem'> /path/to/certificate </intermediateCertificate>
</ssl>
Base Field Communication¶
Base fields cannot be synchronized by the remote modules automatically. This is due to the nature of the Base objects, which can be anything (in C++ they are stored as pointers). This makes it necessary to write and register specialized handlers for fields of each Base type. For each Base type there must be a master handler and a slave handler, which are derived from the classes MLABRemote::BaseMasterHandler and MLABRemote::BaseSlaveHandler (link against MeVisLab::Network in CMake, and include Remote/mlabRemoteBaseHandler.h). The master handler is used for output Base fields (the original object), while the slave handler is used for input Base fields (this generates a mirror object) . The derived handlers must each implement the handleMessage() method, and then send each other (custom) messages to update the state of the Base object in the corresponding handler.
The Base handlers must be registered with MLAB_REGISTER_REMOTE_BASE_HANDLERS and ML_INIT_LIBRARY when the DLL is initialized. It may also be necessary to add new Base field messages for controlling and transferring information about the Base objects if the generic messages are not adequate. Look at the RemoteFileTransfer handler for a simple example.
Existing Base handlers are:
MeVisLab/IDE/Sources/Libraries/MLABNetwork/Remote/mlabRemoteSimpleBaseHandler.h (XMarker, XMarkerList, XMarkerContainer)
MeVisLab/Standard/Sources/Controls/MLABMLItemModelSupport/mlabItemModelRemoteHandler.h
MeVisLab/Standard/Sources/ML/MLRemoteCall/mlRemoteCallInterfaceHandler.h
MeVisLab/Standard/Sources/ML/MLRemoteFileTransfer/mlabRemoteFileTransferHandler.h
MeVisLab/Standard/Sources/ML/MLRemoteRendering/mlabRemoteRenderingHandler.h
Remote Rendering¶
Remote rendering allows for rendering an Open Inventor scene on a MeVisLab server, and viewing and interacting with the scene on a client. This requires that a network which runs remotely contains a RemoteRendering module. The scene is connected to its inventor input. Its output field is a Base field of the type RemoteRendering. This output field must be forwarded to the interface of the macro module that will be run remotely. A RemoteRenderingClient module can be connected to the RemoteRendering output of the remote module in a MeVisLab client, or one can specify a RemoteRendering control in the GUI of the remote module that operates directly on the RemoteRendering field. The Base handler for RemoteRendering fields is already provided by MeVisLab. For details have a look at the source code in MeVisLab/Standard/Sources/ML/MLRemoteRendering.
A similar approach is implemented in the RemotePanelRendering module, but instead of rendering an Open Inventor scene, it renders a MDL panel. This solution does not work perfectly, it might e.g. fail when pop-up windows (context menus, tool-tips) must be shown on the panel.
Example modules are RemoteRenderingCSOExampleModule and RemotePanelRenderingExampleMacro.