Valhalla Legends Forums Archive | Battle.net Bot Development References | Creating a Priority Queue Discussion

AuthorMessageTime
DrivE
Thanks to c0ol for this idea. It was discussed in an earlier post but I am interested in your opinions. Anyway here it is. The idea is to have two different queues. One queue is for normal commands (i.e. talk, kick, resign, unban, etc.) and the other for priority commands (i.e. ban [for ip banning purposes], deisgnate, and the like). I'll call the normal queue Alpha and the priority queue Beta. A script would be written so that any command in the Alpha queue would be executed only after queue Beta is empty. What do you all think of this idea? Thanks

!~!HaZaRD!~!
August 6, 2003, 7:04 PM
K
you really don't need two queues; you need one queue where items are inserted according to priority. if you're using c++ have a look-see at the std::priority_queue template class.
August 6, 2003, 7:17 PM
DrivE
I know that you don't need two queues I was just wondering what people thought of the idea.

!~!HaZaRD!~!
August 6, 2003, 7:42 PM
c0ol
[quote author=K link=board=17;threadid=2226;start=0#msg17230 date=1060197449]
you really don't need two queues; you need one queue where items are inserted according to priority. if you're using c++ have a look-see at the std::priority_queue template class.
[/quote]
uhh, ill disagree. immagine this command:
.say hi\ban jim\say bye\say hi\ban sam\say hi\say bye\ban lamer
would ban jim sam and lamer first
then say hi bye hi hi bye

this is most easily done with 2 or more queues where the highest priority is checked first, if this queue contains any items they are processed. once the top queue is empty the second queue is checked, and so on untill all queues are empty.
August 6, 2003, 8:26 PM
Skywing
[quote author=c0ol link=board=17;threadid=2226;start=0#msg17239 date=1060201597]
[quote author=K link=board=17;threadid=2226;start=0#msg17230 date=1060197449]
you really don't need two queues; you need one queue where items are inserted according to priority. if you're using c++ have a look-see at the std::priority_queue template class.
[/quote]
uhh, ill disagree. immagine this command:
.say hi\ban jim\say bye\say hi\ban sam\say hi\say bye\ban lamer
would ban jim sam and lamer first
then say hi bye hi hi bye

this is most easily done with 2 or more queues where the highest priority is checked first, if this queue contains any items they are processed. once the top queue is empty the second queue is checked, and so on untill all queues are empty.
[/quote]
That is easily implemented with priority_queue. I don't understand why you're wanting to use multiple queues.
August 6, 2003, 8:34 PM
UserLoser
Maybe he thought of the idea that I thought of... Design a bot that loads two bots to the same channel, and both are designed to hold OPs. Example: .ban * could clear 10 users in less than one second from the channel! The bots would simply split up the queue. And for things like .say Hello, it would send 'Hello' from the bot that hasn't sent a message in the longest time out of the two of them.
August 6, 2003, 8:37 PM
K
Re: c0ol

Except with that method you're limited to two options: high priority :: low priority. What if you want to have, say, database update commands performed after kicks / bans but before other output? Add another queue? Not only does having only one (sorted) queue simplify coding and allow you to prioratize a new class of messages without touching your enqueuing / dequeuing routines, it will probably reduce memory usage.
August 6, 2003, 8:40 PM
Stealth
I've implemented this exact system by defining a Priority byte to piggyback each queue array member.

[code]
Public Type udtQueue
Message As String
Priority As Byte
End Type
[/code]

Priority is specified when items are entered into the queue, and the queue is merely looped twice -- first to check for highest-priority messages, if one is found it's sent; if no highest-priority items are found the oldest entry in the queue is delivered to battle.net and the rest are shifted down.
August 6, 2003, 8:41 PM
Skywing
[quote author=UserLoser link=board=17;threadid=2226;start=0#msg17241 date=1060202225]
Maybe he thought of the idea that I thought of... Design a bot that loads two bots to the same channel, and both are designed to hold OPs. Example: .ban * could clear 10 users in less than one second from the channel! The bots would simply split up the queue. And for things like .say Hello, it would send 'Hello' from the bot that hasn't sent a message in the longest time out of the two of them.
[/quote]
His explanation of why he was using multiple queues pretty much rules that out. Besides, you'd still be wanting a priority_queue for each BNCS connection, anyway.
August 6, 2003, 8:41 PM
St0rm.iD
Could have your send() method take an optional parameter which is whether this message is high priority. If so, all the high priority messages go out first, then the rest of the standard priority messages.
August 6, 2003, 8:41 PM
Adron
Nice idea, but make more than two different priorities. Like, a specific ban of a username should probably have a higher priority than a wildcard .ban *, single line responses higher priority than long responses etc.
August 6, 2003, 8:52 PM
MesiaH
I agree with not having 2 seperate queue's, why do that, when you could easily design the queue with more parameters and other options to split them up before sending. Not only would that be better, but with 2 queue's, your more likely to flood a little easier than using just one.
August 7, 2003, 12:40 AM
tA-Kane
[quote author=MesiaH link=board=17;threadid=2226;start=0#msg17266 date=1060216811]Not only would that be better, but with 2 queue's, your more likely to flood a little easier than using just one.[/quote]Not if you don't write it sloppily.
August 8, 2003, 9:56 AM
Camel
[code] With ExecSQL("SELECT TOP 1 id, text " & _
"FROM buffer " & _
"ORDER BY priority DESC, " & _
"id ASC" & _
";")[/code]
August 10, 2003, 3:13 AM
FuZe
If you empty out the priority queue completely, before sending any of the normal queue, hmm, in some cases that might slow down response times a lot. Maybe you mite consider sending three priority queue messages for every 1 normal queue or something similar to that.
August 10, 2003, 3:20 AM
St0rm.iD
[quote author=Camel link=board=17;threadid=2226;start=0#msg17624 date=1060485196]
[code] With ExecSQL("SELECT TOP 1 id, text " & _
"FROM buffer " & _
"ORDER BY priority DESC, " & _
"id ASC" & _
";")[/code]
[/quote]

Do you know how incredibly absofuckingloutly slow that is compared to an in-memory datastructure!? That's such a waste of processing power, probably the string concatenation to build the query has more cycles than a priority queue, not to mention the overhead of sending the query to the database if it is remote, and the parsing of the query string, and the loooong expensive execution of the query, and then parsing back of the result.

In my old chatbot (PhatBot, circa 2000/2001), I implemented a priority queue once to try it out. Basically, I gave anything that started with a / precedence over any normal commands. This didn't work out too well; it was confusing. Instead, I propose any commands or whatever should be queued with a higer priority.
August 10, 2003, 3:22 PM
Camel
[quote author=St0rm.iD link=board=17;threadid=2226;start=15#msg17660 date=1060528961]Do you know how incredibly absofuckingloutly slow that is compared to an in-memory datastructure!?[/quote]

Yes; it is relatively slow. However, it's not too slow to use in practice. Additionally, I don't actually put everything in the sql table; there is a seperate internal buffer -- that buffer is ignored until the internal buffer is empty.
August 10, 2003, 4:38 PM
St0rm.iD
Yeah, but why even use SQL? It's not that hard to write a priority queue, you could probably get one on pscode if you wanted to.
August 10, 2003, 10:13 PM
DarkMinion
That seems to me it would be *far* more inefficient than simply having an internal queue in memory Camel....
August 10, 2003, 10:32 PM
Camel
[quote author=St0rm.iD link=board=17;threadid=2226;start=15#msg17709 date=1060553634]Yeah, but why even use SQL?[/quote]

For one, so I can click people out of the channel from the website. That buffer wont be just for chat messages when I finish it, either.
http://camel.ik0ns.com:400/
August 11, 2003, 12:35 AM

Search