Stanford-Online/class2go — pull request #1880 by sefk (2013-01-15 05:19:19+00:00)
Title: Filesystem caching of S3 locations for files and videos (#1440)

Use a local filesystem cache to store S3 results. Seems to improve performance.

Production settings:

- cache stored on the /mnt filesystem. Two reasons: it's ephemeral disk, we don't care about preserving contents across machine reboots. And it's local disk (not SAN) so hope to have better IO performance.

- file system cache = 4 hours, could be even longer, since we never expect files to change out from under us

- video cache = 30 minutes: this is how long someone might have to wait to see kelvinator results (absence of video files is negatively cached) so it has to be shorter.

Will keep and log some basic stats. Lines like this in the logs every two hours:

cachestats for video_store: hits 23, misses 0, rate 100.0
cachestats for file_store: hits 10, misses 0, rate 100.0

Tested by doing end-to-end file upload/download and video upload/downloads.

Concerns:

- introduces a bug, see #1879.

- I saw the a few of the error below in logs sometimes when doing my end-to-end testing. It looks like it's having trouble flushing something to disk.

```
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 56397)
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 582, in process_request_thread
self.finish_request(request, client_address)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 323, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/Library/Python/2.7/site-packages/django/core/servers/basehttp.py", line 139, in __init__
super(WSGIRequestHandler, self).__init__(*args, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 641, in __init__
self.finish()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 694, in finish
self.wfile.flush()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 303, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe
```