Are listeners actually expensive, or is this a myth?
- John Mela
- Posts: 91
- Joined: Tue Feb 04, 2014 9:50 pm
- Has thanked: 139 times
- Been thanked: 127 times
- Contact:
Are listeners actually expensive, or is this a myth?
I'm considering putting a listener into an object, which would listen to a private (ie large, obscure number) channel for handshaking. There could be 20 or 30 of these objects in a region, but not hundreds.
In testing, I found that 64 objects like that incur no noticeable CPU usage (according to the World graph and Top Scripts) when idle. Obviously, when a message is sent out on that channel there will be processing in the listen() events of the objects, but I'm more concerned about the cost of these scripts when no messages are being sent or received, which would be 99.9% of the time.
Now, listeners have long had a bad reputation in the SL and OpenSim community, with people saying they cause lag, are in short supply, etc. Yet nobody I've ever encountered has been able to quantify these or even verify that there genuinely is a problem in OpenSim code (it's been confirmed by LL that it definitely is a myth in SL, but obviously that's no help to us).
I suspect that a myth may have grown up because of people coding listeners on channel 0, or even on small non-zero channels, which could cause listen() events to fire frequently. And I'm not sure why people say there is a limit on the number of listeners per region.
Can anyone shed any factual light on this?
Thanks!
In testing, I found that 64 objects like that incur no noticeable CPU usage (according to the World graph and Top Scripts) when idle. Obviously, when a message is sent out on that channel there will be processing in the listen() events of the objects, but I'm more concerned about the cost of these scripts when no messages are being sent or received, which would be 99.9% of the time.
Now, listeners have long had a bad reputation in the SL and OpenSim community, with people saying they cause lag, are in short supply, etc. Yet nobody I've ever encountered has been able to quantify these or even verify that there genuinely is a problem in OpenSim code (it's been confirmed by LL that it definitely is a myth in SL, but obviously that's no help to us).
I suspect that a myth may have grown up because of people coding listeners on channel 0, or even on small non-zero channels, which could cause listen() events to fire frequently. And I'm not sure why people say there is a limit on the number of listeners per region.
Can anyone shed any factual light on this?
Thanks!
- These users thanked the author John Mela for the post (total 4):
- Ilan Tochner • Shandon Loring • Zed deTremont • Ada Radius
- Shandon Loring
- Posts: 1348
- Joined: Sat Oct 26, 2013 3:25 am
- Has thanked: 977 times
- Been thanked: 1588 times
- Contact:
Re: Are listeners actually expensive, or is this a myth?
Watching anxiously for comments..
I've always used a number of Listeners for numerous things.
Partly because multi-line scripting workarounds are beyond me, and seem unnecessary.
But then I use llSleep(x) too for the same reason!
But I'm no super-scripter by any means. So..
Watching anxiously for comments..
I've always used a number of Listeners for numerous things.
Partly because multi-line scripting workarounds are beyond me, and seem unnecessary.
But then I use llSleep(x) too for the same reason!
But I'm no super-scripter by any means. So..
Watching anxiously for comments..
- These users thanked the author Shandon Loring for the post:
- Ada Radius
- Oren Hurvitz
- Posts: 361
- Joined: Sun Dec 23, 2012 8:42 am
- Has thanked: 19 times
- Been thanked: 499 times
- Contact:
Re: Are listeners actually expensive, or is this a myth?
Listeners incur almost no cost while they're idle (i.e., while messages aren't sent to them). They do incur some cost when receiving a message, and when adding a new listener. This cost is proportional to the number of listeners on the same channel. For example, if you send a message to a channel that has 30 listeners, it will take x30 CPU as when sending a message to a channel that has only one listener. This is true even if you use filters to limit the listeners, because OpenSim still has to take a look at all of the potential listeners to find the ones you actually want. But using different channels does help, because OpenSim doesn't even look at listeners on other channels than the one that the message was sent to.
The usage cost appears to be pretty low, at least if not too many messages are being sent. Sure, OpenSim has to go over all of the potential listeners, but it can probably do this in a few ms. It only becomes a problem if you have a large number of listeners (hundreds?), or if you send many messages per second.
Caveat: this analysis is based on reading the code; I didn't run tests to judge the real-world performance.
The usage cost appears to be pretty low, at least if not too many messages are being sent. Sure, OpenSim has to go over all of the potential listeners, but it can probably do this in a few ms. It only becomes a problem if you have a large number of listeners (hundreds?), or if you send many messages per second.
Caveat: this analysis is based on reading the code; I didn't run tests to judge the real-world performance.
- These users thanked the author Oren Hurvitz for the post (total 7):
- Selby Evans • Zed deTremont • John Mela • Shandon Loring • Michael Timeless • Tess Juel • Ada Radius
- John Mela
- Posts: 91
- Joined: Tue Feb 04, 2014 9:50 pm
- Has thanked: 139 times
- Been thanked: 127 times
- Contact:
Re: Are listeners actually expensive, or is this a myth?
Many thanks, Oren - this is extremely helpful!
- These users thanked the author John Mela for the post (total 2):
- Shandon Loring • Ada Radius
- Shandon Loring
- Posts: 1348
- Joined: Sat Oct 26, 2013 3:25 am
- Has thanked: 977 times
- Been thanked: 1588 times
- Contact:
Re: Are listeners actually expensive, or is this a myth?
Thank you Benevolent Overseer!
This is cool info, and helps my thought processes for sure.
- These users thanked the author Shandon Loring for the post (total 2):
- John Mela • Ada Radius
- John Mela
- Posts: 91
- Joined: Tue Feb 04, 2014 9:50 pm
- Has thanked: 139 times
- Been thanked: 127 times
- Contact:
Re: Are listeners actually expensive, or is this a myth?
Same here. It's one thing doing a bit of testing and guessing at how it works, and another to hear from someone who really understands the codebase and takes the time and effort to give an informed and detailed answer like that.Shandon Loring wrote: ↑Sun Jul 11, 2021 10:15 pmThis is cool info, and helps my thought processes for sure.
Thanks again, Oren!
- These users thanked the author John Mela for the post (total 2):
- Shandon Loring • Ada Radius
-
- Posts: 1
- Joined: Sat Aug 21, 2021 3:15 pm
- Has thanked: 0
- Been thanked: 4 times
Re: Are listeners actually expensive, or is this a myth?
As Oren said, it is based on how many scripts are listening to a given channel vs how much chatter there is on that channel. Thus, you want to script your device to use randomly obscure channels as much as possible thusly:
integer chan = (integer)llFrand(999999); //picks a random float between 0 and 999,999 then rounds it up to the closest integer.
if you have two devices talking to each other, the one generating the random channel needs to tell the other one what channel to use, so set a standard channel for it to communicate the new channel to switch to.
In device 1:
In device 2:
Device 1 generates the random channel, sends it out on startchan (channel 999), Device 2 hears it, changes channels, turns off the listen on the open channel and starts a listen event on the new randomly chosen channel. Always turn off listens you are not using.
integer chan = (integer)llFrand(999999); //picks a random float between 0 and 999,999 then rounds it up to the closest integer.
if you have two devices talking to each other, the one generating the random channel needs to tell the other one what channel to use, so set a standard channel for it to communicate the new channel to switch to.
In device 1:
Code: Select all
integer setupchan = 999;
integer chan = (integer)llFrand(999999);
llSay(setupchan,(string)chan);
llSetListenEvent(chan,"","","");
Code: Select all
integer chan;
ingeter setupchan = 999;
start_entry()
}
llSetListenEvent(setupchan,"","","");
}
listen(integer channel, key id, string msg, integer num)
{
key owner = llGetOwnerKey(llGetDetected(llGetKey()));
if (owner == llGetOwnerKey(llGetKey()) && channel == startchan )
{
chan = (integer)msg;
llEndListenEvent(0);
llSetListenEvent(chan, "","","");
}
}
- These users thanked the author IntLibber Brautigan for the post (total 4):
- Ilan Tochner • Tess Juel • Graham Mills • Ada Radius
- Tess Juel
- Posts: 360
- Joined: Sun Sep 11, 2016 4:24 pm
- Has thanked: 257 times
- Been thanked: 469 times
Re: Are listeners actually expensive, or is this a myth?
One question about this snippet. In SL it's consdiered good practice to always use negative channels for scripts so it would beIntLibber Brautigan wrote: ↑Sat Aug 21, 2021 3:30 pmIn device 1:Code: Select all
integer setupchan = 999; integer chan = (integer)llFrand(999999);
Code: Select all
integer setupchan = -999;
integer chan = (integer)llFrand(-999999);
- These users thanked the author Tess Juel for the post (total 4):
- Ada Radius • John Mela • Mike Lorrey • Michael Timeless
- Tess Juel
- Posts: 360
- Joined: Sun Sep 11, 2016 4:24 pm
- Has thanked: 257 times
- Been thanked: 469 times
Re: Are listeners actually expensive, or is this a myth?
Tell me if I understand this right. Let's say I have a master switch that turns on and off street lights across the entire sim. Or a master texture changer that switches between seasonal foliages for all trees in the sim. There may well be hundreds, maybe even more than a thousand receivers but there won't be a message sent every day or even every month. Are all those open listens still likely to cause problems?Oren Hurvitz wrote: ↑Sun Jul 11, 2021 7:15 amThe usage cost appears to be pretty low, at least if not too many messages are being sent. Sure, OpenSim has to go over all of the potential listeners, but it can probably do this in a few ms. It only becomes a problem if you have a large number of listeners (hundreds?), or if you send many messages per second.
Last edited by Tess Juel on Sun Aug 22, 2021 5:52 am, edited 1 time in total.
- These users thanked the author Tess Juel for the post:
- Mike Lorrey
- Oren Hurvitz
- Posts: 361
- Joined: Sun Dec 23, 2012 8:42 am
- Has thanked: 19 times
- Been thanked: 499 times
- Contact:
Re: Are listeners actually expensive, or is this a myth?
This won't be a problem, because listeners don't use CPU if no message is being sent on the channel that they're listening to.
When you do send a message on that channel there might be a bit of lag in the world, as the message is sent to hundreds of listeners. But after the message has been sent the lag will disappear.
When you do send a message on that channel there might be a bit of lag in the world, as the message is sent to hundreds of listeners. But after the message has been sent the lag will disappear.
- These users thanked the author Oren Hurvitz for the post (total 5):
- Tess Juel • Ada Radius • John Mela • Mike Lorrey • Michael Timeless