-module(chatbench). -compile(export_all). start() -> code:add_pathz("/Program Files/yaws-1.68/ebin"), application:start(inets), lists:foreach( fun(Pnum) -> spawn(chatbench, client, [Pnum]) end, lists:seq(1, 1000) ). client(Pnum) -> io:format("start~p ", [Pnum]), request(Pnum, 0). request(Pnum, Id) -> Url = "http://localhost:8000/index.yaws?id=" ++ integer_to_list(Id), io:format("~p ", [Pnum]), {ok, {_Status, _Headers, Body}} = http:request(Url), {ok, Json} = json:decode_string(Body), LastId = getlastid(Id, Json), request(Pnum, LastId). getlastid(Id, Json) -> case Json of {array, [_Member, {array, Log}]} -> LastLog = lists:nth(length(Log), Log), {struct, [{id, LastId}, _, _, _]} = LastLog, LastId; _Else -> Id end.