Notes on file access and caching » History » Version 3
Chris Cannam, 2014-03-27 06:41 PM
1 | 1 | Chris Cannam | h1. Notes on file access and caching |
---|---|---|---|
2 | 1 | Chris Cannam | |
3 | 2 | Chris Cannam | 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. |
4 | 2 | Chris Cannam | |
5 | 2 | Chris Cannam | 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. |
6 | 2 | Chris Cannam | |
7 | 2 | Chris Cannam | h2. What the web app does at the moment |
8 | 2 | Chris Cannam | |
9 | 2 | Chris Cannam | The web app has a configuration file which can be found in |
10 | 2 | Chris Cannam | |
11 | 2 | Chris Cannam | <pre> |
12 | 2 | Chris Cannam | WEB-INF/classes/HumanEcho.properties |
13 | 2 | Chris Cannam | </pre> |
14 | 2 | Chris Cannam | |
15 | 2 | Chris Cannam | This specifies directories for input and output files: |
16 | 2 | Chris Cannam | |
17 | 2 | Chris Cannam | <pre> |
18 | 2 | Chris Cannam | indir=/var/lib/tomcat7/webapps/echoapp/WEB-INF/data |
19 | 2 | Chris Cannam | outdir=/tmp/wav |
20 | 2 | Chris Cannam | </pre> |
21 | 2 | Chris Cannam | |
22 | 2 | Chris Cannam | These need to be set correctly when deploying the web application. |
23 | 2 | Chris Cannam | |
24 | 2 | Chris Cannam | The @indir@ should point to the directory containing input data, in this case @hrir_final.mat@. |
25 | 2 | Chris Cannam | |
26 | 2 | Chris Cannam | 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. |
27 | 2 | Chris Cannam | |
28 | 2 | Chris Cannam | h2. Caching |
29 | 2 | Chris Cannam | |
30 | 3 | Chris Cannam | The app now caches all generated files for as long as the server process is running. |
31 | 2 | Chris Cannam | |
32 | 3 | Chris Cannam | It does this by |
33 | 2 | Chris Cannam | |
34 | 3 | Chris Cannam | * 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) |
35 | 3 | Chris Cannam | * 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) |
36 | 3 | Chris Cannam | * moving files from one to the other after the MATLAB process finishes and before serving them to the client |