Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Deterministic playback of a simulation?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Richard Evans  
View profile  
 More options May 17 2012, 10:36 pm
From: Richard Evans <richardprideauxev...@gmail.com>
Date: Fri, 18 May 2012 03:36:05 +0100
Local: Thurs, May 17 2012 10:36 pm
Subject: [erlang-questions] Deterministic playback of a simulation?
I have a multiplayer simulation game running in erlang, involving
multiple characters making decisions etc. Each game instance uses a
few (currently, 4) erlang processes running concurrently,
communicating with an AI simulator written in C.

Everything is working well and I am enjoying using erlang.

But there is one thing I am finding tricky.

For QA purposes, I want to be able to record the exact sequence of
function-calls, so I can play the game back exactly,
deterministically.

My current approach is this: I have a global ets table storing a list
of function-calls. Then, whenever I was calling a function I want to
record - instead of calling the function directly - I call a procedure
which adds the function to the list of function-calls, and then calls
it:

call_and_store(Fun, Args) ->
    add_to_script(Fun, Args);
    apply(lobby, Fun, Args).

add_to_script(Fun, Args) ->
    Info = ets:info(script),
    {size, Size} = lists:keyfind(size, 1, Info),
    io:format("Inserting {~p,~p,~p}~n", [Size,Fun,Args]),
    ets:insert(script, {Size, Fun, Args}).

This approach does not seem to work well because of erlang's
pre-emptive scheduling. If two concurrent processes both invoke
call_and_store, then it is possible (and seems to actually be
happening) that erlang's pre-emptive scheduler may stop processing one
instance of call_and_store between execution of add_to_script and
execution of apply. If this happens, the order of execution and the
order of recorded function-calls will diverge, we don't have an
accurate recording of the set of function-calls, and we won't be able
to deterministically playback.

So my question is: is there a way to prevent the scheduler from
yielding during a block of code? Some way to insist the block is
called as one unit, like this:

call_and_store(Fun, Args) ->
        !!!prevent_yielding,
    add_to_script(Fun, Args);
    apply(lobby, Fun, Args),
        !!!allow_yielding.

My guess is: no. This does not seem very erlangy.

Alternatively, is there a different approach which can produce the
desired list of function-calls? My current approach seems to go
against the erlang grain, involving writing to a shared global table.
Is there a better, more erlangy, way of doing this?

thanks,
~Richard
_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Enrique Paz  
View profile  
 More options May 18 2012, 2:45 am
From: Enrique Paz <quique...@gmail.com>
Date: Fri, 18 May 2012 08:45:14 +0200
Local: Fri, May 18 2012 2:45 am
Subject: Re: [erlang-questions] Deterministic playback of a simulation?

If I get it right, your issue is that the logged function calls might be in
the wrong order. Couldn't you add a timestamp to the call info you are
logging? erlang:now() or os:timestamp/0 (faster) return a timestamp up to
microseconds, then the only action left to do would be ordering your logs
before using them.

2012/5/18 Richard Evans <richardprideauxev...@gmail.com>

--
quique

_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Attila Rajmund Nohl  
View profile  
 More options May 18 2012, 4:49 am
From: Attila Rajmund Nohl <attila.r.n...@gmail.com>
Date: Fri, 18 May 2012 10:49:25 +0200
Local: Fri, May 18 2012 4:49 am
Subject: Re: [erlang-questions] Deterministic playback of a simulation?
2012/5/18 Richard Evans <richardprideauxev...@gmail.com>:
[...]

> For QA purposes, I want to be able to record the exact sequence of
> function-calls, so I can play the game back exactly,
> deterministically.

You could try to trace on the function calls with timestamps.
_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Hynek Vychodil  
View profile  
 More options May 18 2012, 5:04 am
From: Hynek Vychodil <hy...@gooddata.com>
Date: Fri, 18 May 2012 11:04:26 +0200
Local: Fri, May 18 2012 5:04 am
Subject: Re: [erlang-questions] Deterministic playback of a simulation?
Hi.

What about using erlang tracing facility. It hase some nice features.
There will be zero inpact in production code. There will be zero
inpact in production environment if you turn it on only in testing
environment and also there is "automatic" ordering of events. I think
it is best fit for purpose.

Hynek Vychodil

On Fri, May 18, 2012 at 4:36 AM, Richard Evans

_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ulf Wiger  
View profile   Translate to Translated (View Original)
 More options May 18 2012, 7:38 am
From: Ulf Wiger <u...@feuerlabs.com>
Date: Fri, 18 May 2012 13:38:05 +0200
Local: Fri, May 18 2012 7:38 am
Subject: Re: [erlang-questions] Deterministic playback of a simulation?

On 18 May 2012, at 04:36, Richard Evans wrote:

> So my question is: is there a way to prevent the scheduler from
> yielding during a block of code? Some way to insist the block is
> called as one unit, like this:

> call_and_store(Fun, Args) ->
>    !!!prevent_yielding,
>    add_to_script(Fun, Args);
>    apply(lobby, Fun, Args),
>    !!!allow_yielding.

> My guess is: no. This does not seem very erlangy.

No, not at that level.

But you could use e.g.

  global:trans({call_and_store, self()}, fun() -> call_and_store(Fun, Args) end).

See erl -man global

You can specify on how many nodes you want to acquire a lock - default is all connected nodes, but you can set it e.g. to [node()] if that suits you better.

BR,
Ulf W

Ulf Wiger, Co-founder & Developer Advocate, Feuerlabs Inc.
http://feuerlabs.com

_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard Evans  
View profile  
 More options May 18 2012, 12:30 pm
From: Richard Evans <richardprideauxev...@gmail.com>
Date: Fri, 18 May 2012 17:30:00 +0100
Subject: Re: [erlang-questions] Deterministic playback of a simulation?
Thanks guys for all your helpful responses :)

_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »