Prev | Current Page 159 | Next

Brad Ediger

"Advanced Rails"

In the case of database
storage, you may find it more efficient to use a trigger or rule.
Upload progress
One feature that many applications require is upload progress notification: showing
the user a progress bar that indicates how much of the file has been uploaded. This is
surprisingly hard and server-dependent, but there are tools to make it easier. For simplicity,
we will restrict discussion in this section to the Mongrel application server.
Mongrel serializes Rails requests; at any given time, a single Mongrel process can
only execute one Rails request. This is required because ActionController is not
thread-safe. But upload progress requires two simultaneous requests: the upload
itself as well as AJAX requests to check its progress. How do we reconcile this?
The answer is that Mongrel is very conservative about what it locks; it only serializes
requests while they are actually executing controller code. While the file is being
transferred, Mongrel buffers it into memory, but during that time it allows other
* http://cleanair.highgroove.com/articles/2006/10/03/mini-file-uploads
Advanced Database Features | 109
requests to complete. When the file transfer completes, Mongrel processes that Rails
request all at once, only locking during the time the Rails code executes.
The mongrel_upload_progress gem hooks into Mongrel to provide a shared variable
that the multiple requests can use to communicate about the status of file uploads.


Pages:
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171