I'm trying to use batch() to load some data from a slow disk in the background, but it is extremely slow. See code example with timings below. I think it is slower than what can be explained by the overhead of communicating with the worker (consider that I am not even transferring the loaded data from the worker to the client in the example).
>> a = rand(512, 512, 1000);>> save('a');>> tic; load('a'); tocElapsed time is 5.574926 seconds.>> tic; b = batch(@load, 1, {'a'}); toc; tic; wait(b); toc;Elapsed time is 0.444297 seconds.Elapsed time is 41.229590 seconds.
You can see that the time until the batch job is done is more than 35 s longer than the same operation on the client. This is not because a new Matlab worker has to be started — in my example, a worker was already running (if no worker were running, the batch(…) command itself would take longer, not the wait(b)).
Where does this overhead come from? How can I avoid it? (I also tried parfeval, but parfeval is plagued by a memory leak that makes it unusable — confirmed as a known bug by MathWorks).
Thanks, Matthias
Best Answer