Eggheads: A putslow ?

wanderer wanderer at powersource.cx
Thu Aug 26 09:00:04 CST 2004


'llo

Another helpful thing might be the tcl trace command.
This will allow you to only check the buffer when needed.
eg:
a line is added to the list : trace calls the buffercheck proc
the line is sent, if it's allowed to. (eg: 5 seconds have passed since the 
last send)
when a line is sent, you start a timer which will check the buffer again in 
X seconds.
if no lines are left: don't do a timer.

Here's something i cooked up, when in need for a delayed WHOIS query.
# The whois buffer trace function
proc CheckBuffer {var b op} {
   variable checklist
   variable pb
   if {!$pb(stopQ)} {
     if {[d]} {putlog "DoWhois: Check Whois buffer"}
     set pb(stopQ) 1
     after [set t [expr $pb(buffertime) * 1000]] {::PowerBan::DoWhois}
     after [expr $t - ($pb(buffertime) * 20)] {set ::PowerBan::pb(stopQ) 0}
   } {
     if {[d]} {putlog "DoWhois :Not doing a whois... The buffer is busy."}
   }
}

# The whois buffer itself
proc DoWhois {} {
   variable pb
   variable checklist
   if {[d]} {putlog "DoWhois: The buffer proc was triggered. Why?"}
   if {[info exists checklist]&&[llength $checklist]} {
     if {[d]} {putlog "DoWhois: Seems that a whois can be done. Whoissing: 
[join [lrange $checklist 0 4] ","]"}
     putquick "WHOIS [join [lrange $checklist 0 4] ","]"
     set checklist [lreplace $checklist 0 4]
   } {
     if {[d]} {putlog "DoWhois :Not doing a whois... The buffer is empty."}
   }
}
trace add variable [namespace current]::checklist write [namespace 
current]::CheckBuffer

The trace will cause a timer to be started with every item lappended to 
CheckBuffer.

Have fun

wanderer


At 16:40 26/08/2004, you wrote:

>Thanks gents.
>
>Much easier than I imagined, once I understood what commands to look at :)
>
>On Thu, 26 Aug 2004 12:10 pm, BarkerJr wrote:
> > >>I'm looking for ideas on how to queue up potentially a large number of
> > >>messages, and feed them out 1 per X seconds (probably 45 or 60). While
> > >> I am reasonably competent with TCL, I'm stumped on ways to achieve
> > >> this.
> > >
> > > Off the top of my head:
> > >
> > > Have a global list you add lines to that you want to send.  Have a
> > > timer or TIME bind that runs a proc that removes the first line from
> > > the list, sends it, then sets a timer again to call the proc X number
> > > of seconds later.  Your other procs can then just add lines to this
> > > list.
> >
> > I have a script that does this somewhat.  The idea is that if you develop
> > lots of queues, you don't need to worry about speeds, just send the most
> > important queues first.
> >
> > ftp://barkerjr.net/pub/irc/eggdrop/Scripting/scripts/queues.tcl.tar.bz2




More information about the Eggheads mailing list