Forum: Ruby on Rails Re: Ajax and performance . . progress bar pattern

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
6165aecb1a97c3ee6df433e38b49ca37?d=identicon&s=25 Blake Miller (Guest)
on 2007-03-20 21:48
(Received via mailing list)

Had a very similar task, a progress bar updating in the browser while
long-running task is running on the server. WEBrick can only server one
request at a time, which explains the behavior you describe . . . all
"update progress bar" requests get processed after the long-running
is completed. You may be interested in Apache and mod_fcgid . . . you
run multiple Rails dispatchers (basically a separate ruby instance for
though they are not really ruby processes, they are threads which are
managed by mod_fcgid)

Then your progress bar can work, but there's still a caveat: these
dont share any memory because that was not part of the design of Rails
is what is mean by "not thread-safe"). The way to do it is to put the
progress bar value in the session, and in your long-running action, call
session.update after setting the progress value. The progress meter is
just some AJAX polling (PeriodicallyCallRemote) calling an action which
renders the progress meter. If you dont call session.update, Rails calls
for you after the action completes, but in this case you will want to
it, since you need that progress value to be available to ALL the
threads before your long-running action completes.

Hope that helps.

Blake Miller
EnFlex Corp
(928) 776-7101
This topic is locked and can not be replied to.