ticks and performance

11 views
Skip to first unread message

Nathan Smith

unread,
Apr 3, 2019, 5:53:01 PM4/3/19
to MOO Talk
Hi there,
In my effort to better understand in-depth coding knowledge as it aattains to efficiency, I started reading more into ticks.
Trying to figure out exactly what they are.
I know what a tick is in terms of a processor, it is an operation. If you have a CPU that is 2.7 GHZ, it could do 27000000 operations of 1+1, or there abouts if I recall. Something along  those lines.
Similarly in moo, a tick is an operation. Hencehence, eval 1+1 uses 1 tick.
Why, then, do tasks get aborted after x ticks. I've read in places 20000, others 30000 and others 60000.
The server itself says ticks based on server CPU seconds.
For the case of simplicistsimplicity, lets say 30,000. This means, theoretically, a task could do 30,000 lines of 1+1's because before it errored. But why?
What does this prevent.
there's clearly a reason for it.
Does it start hogging resources?
Should all verbs, no matter of what they do, use under x ticks for optimum server performance? Is there a "if your task goes about x ticks, you're doing something wrong?"
again, and must be true, is that my coding style is not efficient. To that end, I want to figure out why.
I hope someone will be able to offer some advisce.
Nate

Michael Munson

unread,
Apr 3, 2019, 5:58:21 PM4/3/19
to Nathan Smith, MOO Talk
Yes, basically. The way MOO handles process interleaving is that anytime a verb does certain operations, mainly calling another verb or suspending then the MOO virtual machine lets another verb run for a while. Therefore, it would be possible to design a MOO verb that did nothing but an infinite loop that would block the whole game. Hence the need for terminating tasks if they run too long. Suspending resets the tick count because when you suspend it allows another process to run and puts the currently running verb in the execution stack.

--
You received this message because you are subscribed to the Google Groups "MOO Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to MOO-talk+u...@googlegroups.com.
To post to this group, send email to MOO-...@googlegroups.com.
Visit this group at https://groups.google.com/group/MOO-talk.
For more options, visit https://groups.google.com/d/optout.

Steven Owens

unread,
Mar 27, 2020, 10:38:22 AM3/27/20
to MOO Talk
Yes, ticks are a crude, but as it turns out, like much of MOO, surprisingly workable solution for CPU resource hogging.

According to either Pavel Curtis or Stephen White, back in the day, I can't quite remember which, the number of ticks per operation was mostly chosen by feel/judgement call as to how expensive the operation was.

I don't know if anyone did any further measuring and tweaking of these numbers over the years.

Each user's verb is started with a certain number of ticks, which it uses up with operations, and are gradually replenished over time.  I'm sure the initial number is tunable, probably at compile time. 

If a verb execution ran out of ticks, it threw an error.

MOO coders who wanted to do expensive/long-lived verbs would proactively use suspend() to allow ticks to replenish.  The LambdaMOO wizards added a utility verb, suspend_if_needed(n) which would suspend for n seconds if the tick count was running out. Wizards generally recommended that n be more than 10, or invoking the utility verb probably cost as many ticks as you recovered.

Of course CPUs are ridiculously faster, these days.

Steven J Owens


C Oda

unread,
Mar 27, 2020, 10:53:13 AM3/27/20
to MOO Talk
As someone not familiar with the MOO or MUD ecosystem in general, is this "tick" mechanism more common or is this unique to MOO?

Also, is it possible to serialize the representation of a suspended process and restore it later?

Tim van Dijen

unread,
Mar 27, 2020, 11:50:27 AM3/27/20
to MOO-...@googlegroups.com
Hi Steven,

On 26-3-2020, 00:40 Steven Owens wrote:
> Each user's verb is started with a certain number of ticks, which it
> uses up with operations, and are gradually replenished over time.  I'm
> sure the initial number is tunable, probably at compile time.
>
You can set it in options.h, but you can also override that value in-MOO
with a property on $server_options:

https://www.hayseed.net/MOO/manuals/ProgrammersManual.html#SEC70


- Tim

Tim van Dijen

unread,
Mar 27, 2020, 11:54:00 AM3/27/20
to MOO-...@googlegroups.com

It stems from CPU-ticks, where each operation in machine language would require one CPU-tick.

- Tim

Op 27-3-2020 om 15:44 schreef C Oda:
As someone not familiar with the MOO or MUD ecosystem in general, is this "tick" mechanism more common or is this unique to MOO?

Also, is it possible to serialize the representation of a suspended process and restore it later?
--
You received this message because you are subscribed to the Google Groups "MOO Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to MOO-talk+u...@googlegroups.com.

Michael Munson

unread,
Mar 27, 2020, 7:33:37 PM3/27/20
to Steven Owens, MOO Talk
MOO’s implementation of ticks is necessary because MOO only runs one verb at a time. It doesn’t appear that way from players perspective because any time a verb finishes or suspend() is called the next verb in the execution stack is executed.

What this means is that if you just made a infinite loop in a verb and ran it the entire MOO would be blocked, causing it to freeze. Counting ticks and stopping any process that exceeded the limit is a way to prevent this from happening. The ticks aren’t increased over time but are renewed every time you call suspend() because that lets another verb have a turn at executing and that’s the only thing the MOO cares about. 

This is actually the same kind of pseudo multi processing that Windows 3.14 used, if you’re curious.

--
You received this message because you are subscribed to the Google Groups "MOO Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to MOO-talk+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages