[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: CPU/Memory limiting

M. Edward (Ed) Borasky

7/8/2007 1:26:00 AM

TongKe Xue wrote:
> Hey Everyone,
>
> I'm working on a massive simulation project (like worldforge). I need to
> be able to allow users to script objects in the world. I am thinking of
> ussing Ruby as my scripting language of choice. However:
>
> (1) I need to be able to limit the memory usage of the object.
> (2) I need to be able to limit the CPU cycle usage of the object.
>
> I.e. I don't want users to use my game to calculate digits of PI.
>
> Is there a way (or an existing implemntation of Ruby) to let me create
> these light-weight tasklets/threadlets/processlets (there's too many
> objects
> to have a UNIX process for each object) such that I can limit the
> memory/cpu
> usage on each?
>
>
> Thanks,
> --TongKe
>

I don't think it's possible to use *any* Turing-complete scripting
language in such a manner, let alone Ruby. You'd be better off designing
your own language based on finite-state machines, for which you *can*
impose such control.

1 Answer

M. Edward (Ed) Borasky

7/8/2007 4:29:00 AM

0

TongKe Xue wrote:
> I think there is a misunderstanding.
> My goal is not to enforce these limits at compile time.
>
> My goal is to enforece these limits at run time.
>
> You exceed the memory limit? I don't allow you to allocate more memory.
> You exceed your cpu slice? I swap you out and run another thread for a
> while.

As another poster pointed out, this is an operating-system-dependent
function, not one that belongs in a portable high-level language. So you
now need a system administrator to detect when a process is being a CPU
or memory hog and take some kind of action.

This is *exactly* what an OS does for a living! I don't know how to do
this on a Windows server, but on Linux and most other Unix-like systems,
there is a gizmo called "ulimit". This allows you to set a policy on how
big a process can get or how much total CPU time it can accumulate. The
bad news is that, as far as I know, when the process *does* violate its
ulimit, it is unceremoniously terminated and expunged from the system.
If that kind of behavior is compatible with your game, great. Otherwise,
you'll have to find a way to trap the ulimits and deal with them.

In any event, I think you're making this hard for yourself. There are
existing simulation game frameworks that work very well, and I think
there are even some with Ruby bindings. It sounds to me like you're
trying to reinvent some wheels rather than designing a user experience.
I'd recommend getting a good handle on the "whats" first before delving
much deeper into the "hows".