[erlang-questions] Thread creation benchmark

Tim Watson watson.timothy@REDACTED
Thu Jan 10 13:16:01 CET 2013


On 10 Jan 2013, at 12:11, Xiao Jia wrote:

> On Thu, Jan 10, 2013 at 11:59:25AM +0000, Tim Watson wrote:
>> On 10 Jan 2013, at 05:05, Xiao Jia wrote:
>> 
>>> The idea is to create M x N threads, and measure the time cost for
>>> every N threads created. After a thread is created, it sends a message
>>> to let the main process continue, and finishes execution.
>>> 
>> 
>> Why do you make the main thread wait for each thread to respond that it has started? Aren't you therefore measuring the time it takes for the communication with to the 'creator' to take place as well in this case? That's not measuring process creation time, it's measuring that *plus* the time it takes to enqueue a response and for the main process to dequeue that message, plus of course the effect that scheduling has on all of this.
>> 
>> The expression `[spawn(fun() -> (receive stop -> ok end) end) || _ <- lists:seq(1, N)]` will measuring creation time only. You can use timer:tc and the value of N to calculate the average cost.
>> 
>> Spawning is essentially an asynchronous operation, and the semantics aren't defined except that you get back a process identifier once the process is *alive*. The use of erlang:spawn/1 therefore *does* measure the cost of spawning a process properly, thus timer:tc with spawn/1 is a reasonable way to measure this I think.
> 
> Thanks. You are right, that's not only creation time. I merely test
> something not computation intensive but appears frequently. 

I'm not sure what you mean by this, but then I'm not really sure what you're trying to measure either. Presumably you're measuring in order to help make design decisions about the code you're writing, so it may be more helpful if you explain what you're trying to achieve so we can suggest the best kind of benchmarks for your needs.

Cheers,
Tim


More information about the erlang-questions mailing list