Notes on file access and caching¶
When running a MATLAB function in the MATLAB Compiler Runtime environment, it seems to be good practice to avoid using the current working directory. When the function is run it is first unpacked into a temporary cache location whose location is not predictable.
Rather than try to discover that location so that an external process can feed input files to the function and receive outputs, it seems more reliable to tell the MATLAB code what directory to use for its input and output files.
What the web app does at the moment¶
The web app has a configuration file which can be found in
WEB-INF/classes/HumanEcho.properties
This specifies directories for input and output files:
indir=/var/lib/tomcat7/webapps/echoapp/WEB-INF/data outdir=/tmp/wav
These need to be set correctly when deploying the web application.
The indir
should point to the directory containing input data, in this case hrir_final.mat
.
The outdir
should point to a directory writable by the Tomcat process owner, in which the MATLAB code will put its generated files. The app won't be able to create this directory or to use it if it has the wrong permissions, so it's up to the user deploying the site to handle that.
Caching¶
The app now caches all generated files for as long as the server process is running.
It does this by
- keeping a central location for successfully generated files, with names uniquely identifying their generation parameters, and serve audio from that if it is found there (this is the
outdir
mentioned above) - keeping a separate location for the MATLAB process to write its outputs in, different from the above so that we don't serve any half-written files (this is a uniquely-named subdirectory of
outdir
for each MATLAB invocation) - moving files from one to the other after the MATLAB process finishes and before serving them to the client