Improve container teardown sequence
We already use a separate mechanism for getting logs incrementally. Given performance concerns (docker operation latency and concurrency), we should use that mechanism for getting logs on container shutdown as well.
Also, the teardown code was called synchronously from the caller which causes blocking. A future was proposed but then we lose control over the scheduling. Instead, we can delegate this task to the nanny thread which is already performing a similar activity.
Have we thought about moving away from the "read the logs from file directly" approach yet? I think we had some discussions around splitting the activation in two parts, one being the result + metadata and the other being the logs. If we'ld save the result first and then fetch the logs asynchronously we could move "log getting" off the critical path and use docker logs there, as speed doesn't matter that much anymore. That'ld make us interfaced through Docker APIs solely.
The "result" part of an activation is already separate from the logs and has never been part of the log as it is sent back on the POST - along with the metadata. However, the activation record from the invoker is written once and so it is still on the critical path anyhow. That's the latency aspect but equally serious is the overall performance issue. In various versions of docker, we have noted significant delay in other docker operations when docker log was in use (both latency and general slowness) and so moved away from it. This is in relation to both docker log and docker log --follow. Of course docker 1.11 might be better but we are not on that yet.
At a higher level, the point of this PR is to unify the way we get logs in the invoker. Whether we do it from the filesystem or via the docker API, we should not be doing both as we are now. So I think we should consolidate that first and in the future move (all at once) to possibly other logging mechanisms.
Daniel is investigating other potential remedies for the future including streaming it out or using an external nanny agent to recover logs. Whatever we decide on, I hope we can use just that mechanism.
Thanks for the background information on docker logs. Definitly agreeing on using just one mechanism.