[erlang-questions] negative diference between two calls to now/0

Rodrigo Ahumada M. <>
Mon Feb 5 05:08:55 CET 2007


hi

i was writing a short erlang program to make a test for a sofware for a
friend. I wanted to test how many connections his server can handle per
second, and how long it takes to respond and serve.

so i made a program that launches N processes that tries to conect to
the server, send question and receive an answer. After that the process
send its results to a logger process and then terminates.

the code for each process is like this:

[...]

time_lapse({_MgS1, S1, MuS1}, {_MgS2, S2, MuS2}) ->
  %% calculate the difference of msecs,
  %% ignore the MegaSecs because always they're zero
  T1 = S1*1000 + MuS1,
  T2 = S2*1000 + MuS2,
  T2 - T1.


client_proc(IP, Port, Timeout) ->
  InitProc = now(),   %% timestamp when the process started
  case gen_tcp:connect(IP, Port, [list, {active, false}], Timeout) of
    {ok, Socket} ->
      InitCnx = now(),  %% timestamp when the process could connect
      gen_tcp:send(Socket, ?QUESTION),
      case gen_tcp:recv(Socket, 0) of
        {ok, _Answer} ->
          EndCnx = now(), %% timestamp when the process received an 
                          %% answer...
          inet:close(Socket),
          WaitedTime = time_lapse(InitProc, InitCnx),
          ServedTime = time_lapse(InitCnx, EndCnx),	
          logger ! {success, WaitedTime, ServedTime};

        {error, _Reason} ->
          EndProc = now(), %% timestamp when the server connected but 
                           %% close the conection before the answer
          WaitedTime = time_lapse(InitProc, EndProc),
          logger ! {failed, WaitedTime}
      end;

      {error, _Reason} ->
        EndProc = now(), %% timestamp when the process gave up trying 
                         %% to connect
        WaitedTime = time_lapse(InitProc, EndProc),
        logger ! {failed, WaitedTime}
		
  end,
  client_launcher ! {terminated, self()}.

[...]

th problem i'm having is some times time_lapse/2 gives me a negative
number, when calculating WaitedTime and ServedTime.

thanks for any help or idea.



	

	
		
__________________________________________________ 
Preguntá. Respondé. Descubrí. 
Todo lo que querías saber, y lo que ni imaginabas, 
está en Yahoo! Respuestas (Beta). 
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas 




More information about the erlang-questions mailing list