The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 21, 2013, 11:04:27 AM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Best way to do job queue?  (Read 816 times)
kurdt
Lifer
*****
Offline Offline

Posts: 1153


paha arkkitehti


View Profile
« on: January 31, 2010, 11:24:20 PM »

I have been thinking about job queue and how to do it. My idea is that I do a simple table with columns "task" and "status". Then I have a task_delegator script that reads that table and it has preconfigured tasks built-in. Task column tells it what needs to be done and status tells it whether task has been started by another task_delegator already or is it available. When task is done, it's logged and removed from queue.

But how do I keep this under control so that server doesn't get bogged down because there just happens to be X amount of resource intensive tasks running? One idea is that I could read some current stats for CPU in task_delegator and then decide if to proceed. Then what to do if some task goes to infinite loop? Here I can't think anything except that task scripts should be done so well that they don't get stuck in infinite loop or something Wink
Logged

I met god and he had nothing to say to me.
Phaėton
Lifer
*****
Offline Offline

Posts: 544


⎝⏠⏝⏠⎠


View Profile
« Reply #1 on: February 01, 2010, 07:21:54 AM »

im curious to see what is said about this as well... doesnt the system handle cpu
load balancing? Well.. all the tasks that start something your afraid of entering the infinite loop
could throw out a 'hey im going in the cave' record somewhere.. and then a seperate task
once or twice a day to make sure that everyone that went into a cave came out and
took down their own flag.

interested to see where this one goes... is this on a *amp box?
Logged

When I was your age we used to walk to the TV to change the channel....  _̴ı̴̴̡̡̡ ̡͌l̡̡̡ ̡͌l̡*̡̡ ̴̡ı̴̴̡ ̡̡͡|̲̲̲͡͡͡ ̲▫̲͡ ̲̲̲͡͡π̲̲͡͡ ̲̲͡▫̲̲͡͡ ̲|̡̡̡ ̡ ̴̡ı̴̡̡
kurdt
Lifer
*****
Offline Offline

Posts: 1153


paha arkkitehti


View Profile
« Reply #2 on: February 01, 2010, 07:31:45 AM »

im curious to see what is said about this as well... doesnt the system handle cpu
load balancing?
It does but the point is that it just doesn't start new tasks if there's already 10 tasks taking 100% CPU. Instead get those done before getting next one in works.

Quote
Well.. all the tasks that start something your afraid of entering the infinite loop could throw out a 'hey im going in the cave' record somewhere.. and then a seperate task
once or twice a day to make sure that everyone that went into a cave came out and took down their own flag.
That could work. Mainly I'm afraid of the 3rd party stuff that might go apeshit. I have some exec stuff there that I just can't avoid.

Quote
is this on a *amp box?
Kinda.. basic PHP & MySQL on mainly Debian.
Logged

I met god and he had nothing to say to me.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10009



View Profile
« Reply #3 on: February 01, 2010, 08:03:03 PM »

@ loading the CPU: What kind of tasks are we talking about K? If they are network tasks, then the natural bottleneck of the 'net will help you out. Other than that, if you cron something to hit once per minute and then only do (n) jobs, perhaps even instituting a little bit of sleep in the process, you'll be alright.

This is pretty much exactly how my queuing systems work. I upgraded a bit ago to implement stored procedures in MySQL to make sure there's never a race condition, and I can go from one handler to any number of handlers without having DB problems.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #4 on: February 01, 2010, 11:15:36 PM »

i have a task that fires every 5 minutes.
however, its a beast of a task, and if the server is under load, it will cause a domino effect that will never recover, getting slower and slower.

So... I check the server load in /proc/loadavg and make sure its under an upper limit.
Actually a few tasks do this, but it was done initially for a specific one.
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10009



View Profile
« Reply #5 on: February 01, 2010, 11:39:21 PM »

My eblaster does that, but just a little differently. I do a shell_exec('ps aux') and see if there are any of (me) running and if so, halt - making it sort of ghetto singleton.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
Phaėton
Lifer
*****
Offline Offline

Posts: 544


⎝⏠⏝⏠⎠


View Profile
« Reply #6 on: February 02, 2010, 12:26:53 AM »

I was gonna suggest a ps aux but i wasnt sure if its available on debian...
Logged

When I was your age we used to walk to the TV to change the channel....  _̴ı̴̴̡̡̡ ̡͌l̡̡̡ ̡͌l̡*̡̡ ̴̡ı̴̴̡ ̡̡͡|̲̲̲͡͡͡ ̲▫̲͡ ̲̲̲͡͡π̲̲͡͡ ̲̲͡▫̲̲͡͡ ̲|̡̡̡ ̡ ̴̡ı̴̡̡
walrus
Rookie
**
Offline Offline

Posts: 46


View Profile
« Reply #7 on: February 02, 2010, 04:46:13 AM »

Code:
//this gets the current load - but what nutballs said with proc/loadavg might be better
function get_load()
{
preg_match('/average: (.+?),/',`uptime`,$out);
return $out[1];
}

//this counts how many times $filename is already running
$running_count = `ps aux | grep -i $filename |grep -v grep| wc -l`;


Logged
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!