Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
queuing work in a web app (sinatra/webrick)
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  10 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Gurpal 2000  
View profile  
 More options Nov 12, 5:44 pm
Newsgroups: comp.lang.ruby
From: Gurpal 2000 <g...@gurpal.co.uk>
Date: Fri, 13 Nov 2009 07:44:14 +0900
Local: Thurs, Nov 12 2009 5:44 pm
Subject: queuing work in a web app (sinatra/webrick)
Hi

I want to make a webapp that allows users to queue bit of work
(converting video for example). They are also able to see the queue at
any time and check the progress (queued|processing|done) and are able to
REORDER items in the queue.
The queue can be stopped (ie. paused) and resumed in between conversions
of course.

I'm using sintatra and the LoopingThread example from here
http://codeidol.com/other/rubyckbk/Multitasking-and-Multithreading/Te...

Im sure there's ppl out there who've done something similar. I can do
this in java no problem (synchronized lists etc) but not sure how to do
this in ruby as im sort of a newbie.

I have a working bit of code but im sure im missing something (memory
leak, synchorizing issues etc). Can post more code (very small) if
someone's willing to help.

Thanks!
--
Posted via http://www.ruby-forum.com/.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gurpal 2000  
View profile  
 More options Nov 12, 5:45 pm
Newsgroups: comp.lang.ruby
From: Gurpal 2000 <g...@gurpal.co.uk>
Date: Fri, 13 Nov 2009 07:45:18 +0900
Local: Thurs, Nov 12 2009 5:45 pm
Subject: Re: queuing work in a web app (sinatra/webrick)

Oh and i forgot to mention that the queue can be persisted if u want - i
dont care at this stage. But im essentially keeping the queue in a flat
file on disk to hopefully get some 'cheap locking'. I'd like to do this
without a DB so to speak.

thx
--
Posted via http://www.ruby-forum.com/.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gurpal 2000  
View profile  
 More options Nov 12, 5:46 pm
Newsgroups: comp.lang.ruby
From: Gurpal 2000 <g...@gurpal.co.uk>
Date: Fri, 13 Nov 2009 07:46:30 +0900
Local: Thurs, Nov 12 2009 5:46 pm
Subject: Re: queuing work in a web app (sinatra/webrick)
snip..

OK i altered my code to use Sequel.sqlite. So now i have my "list" in
memory. So now the queue implementation is the issue. thx
--
Posted via http://www.ruby-forum.com/.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tony Arcieri  
View profile  
 More options Nov 12, 7:00 pm
From: Tony Arcieri <t...@medioh.com>
Date: Fri, 13 Nov 2009 09:00:48 +0900
Local: Thurs, Nov 12 2009 7:00 pm
Subject: Re: queuing work in a web app (sinatra/webrick)

On Thu, Nov 12, 2009 at 3:46 PM, Gurpal 2000 <g...@gurpal.co.uk> wrote:
> OK i altered my code to use Sequel.sqlite. So now i have my "list" in
> memory. So now the queue implementation is the issue. thx

Are you wanting to farm out work among a distributed network of agents?
Nanite + RabbitMQ comes to mind:

http://github.com/ezmobius/nanite

--
Tony Arcieri
Medioh/Nagravision


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gurpal 2000  
View profile  
 More options Nov 12, 8:01 pm
Newsgroups: comp.lang.ruby
From: Gurpal 2000 <g...@gurpal.co.uk>
Date: Fri, 13 Nov 2009 10:01:35 +0900
Local: Thurs, Nov 12 2009 8:01 pm
Subject: Re: queuing work in a web app (sinatra/webrick)

Tony Arcieri wrote:
> On Thu, Nov 12, 2009 at 3:46 PM, Gurpal 2000 <g...@gurpal.co.uk> wrote:

>> OK i altered my code to use Sequel.sqlite. So now i have my "list" in
>> memory. So now the queue implementation is the issue. thx

> Are you wanting to farm out work among a distributed network of agents?
> Nanite + RabbitMQ comes to mind:

> http://github.com/ezmobius/nanite

not really farm out, i'll check this out but mq sounds over the top for
what's essentially a small home project (for now)
--
Posted via http://www.ruby-forum.com/.

    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard Conroy  
View profile  
 More options Nov 13, 12:22 am
From: Richard Conroy <richard.con...@gmail.com>
Date: Fri, 13 Nov 2009 14:22:12 +0900
Local: Fri, Nov 13 2009 12:22 am
Subject: Re: queuing work in a web app (sinatra/webrick)

There are numerous solutions for this kind of task: BackgroundJob,
DelayedJob,
Workling etc. The list is quite extensive.

My personal opinion is that spinning off threads to do this work is not the
way to
go about it. To my mind this is an activity that should be spun off in a
separate
process.

While you want to avoid using the DB for this, I think you should
reconsider:
DB backed scheduling gets your locking and monitoring via
transactions/persistence and
it doesn't have to be difficult either. I would look for a background
scheduling tool
that implicitly uses your DB so that you don't get your hands dirty.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gurpal 2000  
View profile  
 More options Nov 18, 5:24 pm
Newsgroups: comp.lang.ruby
From: Gurpal 2000 <g...@gurpal.co.uk>
Date: Thu, 19 Nov 2009 07:24:18 +0900
Local: Wed, Nov 18 2009 5:24 pm
Subject: Re: queuing work in a web app (sinatra/webrick)
OK i managed to use Sequel DB. But the backgroundjob api etc seems
overkill. This LoopingThread works below, but i noticed 100% usgae on
ruby 1.8.6. Is this normal?

class LoopingThread < Thread
  def initialize
    @stopped = false
    @paused = false
    super do
      before_loop
      until @stopped
        yield
        Thread.stop if @paused
      end
      after_loop
    end
  end

  def before_loop
  end

  def after_loop
  end

  def stop
    @stopped = true
  end

  def paused=(paused)
    @paused = paused
    run if !paused
  end
end
--
Posted via http://www.ruby-forum.com/.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Robert Gleeson  
View profile  
 More options Nov 18, 8:25 pm
Newsgroups: comp.lang.ruby
From: Robert Gleeson <r...@flowof.info>
Date: Thu, 19 Nov 2009 10:25:03 +0900
Local: Wed, Nov 18 2009 8:25 pm
Subject: Re: queuing work in a web app (sinatra/webrick)
Hi,

I would guess your culprit for the spike to 100% CPU usage may be your
infinite loop:

>      until @stopped
>        yield
>        Thread.stop if @paused
>      end

Look at using sleep() if you want to decrease CPU usage. Even sleeping
for one second should decrease your CPU usage dramatically in my
experience(maybe with a rare spike).

--
Posted via http://www.ruby-forum.com/.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gurpal 2000  
View profile  
 More options Nov 18, 8:32 pm
Newsgroups: comp.lang.ruby
From: Gurpal 2000 <g...@gurpal.co.uk>
Date: Thu, 19 Nov 2009 10:32:39 +0900
Local: Wed, Nov 18 2009 8:32 pm
Subject: Re: queuing work in a web app (sinatra/webrick)

Robert Gleeson wrote:
> Hi,

> I would guess your culprit for the spike to 100% CPU usage may be your
> infinite loop:

>>      until @stopped
>>        yield
>>        Thread.stop if @paused
>>      end

> Look at using sleep() if you want to decrease CPU usage. Even sleeping
> for one second should decrease your CPU usage dramatically in my
> experience(maybe with a rare spike).

Sure, i got this code from the Oreilly Ruby Cookbook. Is it bad code
then?
Again this doesn't happen when i use similar code in Java...
--
Posted via http://www.ruby-forum.com/.

    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Robert Gleeson  
View profile  
 More options Nov 18, 8:45 pm
Newsgroups: comp.lang.ruby
From: Robert Gleeson <r...@flowof.info>
Date: Thu, 19 Nov 2009 10:45:24 +0900
Local: Wed, Nov 18 2009 8:45 pm
Subject: Re: queuing work in a web app (sinatra/webrick)
> Sure, i got this code from the Oreilly Ruby Cookbook. Is it bad code
> then?

The book seems to be a little outdated - for example, i rarely see
people defining setters themselves nowadays, especially when you can use
attr_writer :pause . I'm not sure why they didn't pick up on what could
be an infinite loop, or at least a loop that can repeat itself many,
many times.

> Again this doesn't happen when i use similar code in Java...

I don't know why that is in Java - in C, Ruby, an infinite loop is going
to consume a lot of CPU power unless you take precautions.

--
Posted via http://www.ruby-forum.com/.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google