Thanks Konstantin. You are right about the parsing function of the json. I use mnesia and update functions are below;
update(player,WEBSOCKETID,PACK)->
case fgen:db_hd(boss_db:find(jamir_match_data,[{match_id,'equals',lists:nth(1,PACK)}])) of
[] -> [];
EXT -> PlayerData = EXT:player_data(),
{WSID, ALLDATA} = lists:keyfind(list_to_binary(pid_to_list(WEBSOCKETID)),1,PlayerData),
NEWDATA = setnth(3 , ALLDATA , fgen:remove(1,PACK)),
fgen:updateDB(
EXT,[
{ player_data, lists:keyreplace(list_to_binary(pid_to_list(WEBSOCKETID)), 1, PlayerData , {list_to_binary(pid_to_list(WEBSOCKETID)), NEWDATA}) },
{ response_data, lists:sublist(EXT:response_data(),5) ++ [1] ++ lists:nthtail(6,EXT:response_data()) }
]
)
%randomArenaActions(EXT)
end;
update(bullet,WEBSOCKETID,PACK)->
case fgen:db_hd(boss_db:find(jamir_match_data,[{match_id,'equals',lists:nth(1,PACK)}])) of
[] -> [];
EXT -> ResponseData = EXT:response_data(),
fgen:updateDB(
EXT,[
{bullet_data, EXT:bullet_data() ++ [{list_to_binary(pid_to_list(WEBSOCKETID)),fgen:remove(1,PACK)}]},
{response_data, lists:sublist(ResponseData,6) ++ [1] ++ lists:nthtail(7,ResponseData)}
]
)
end.
I think it is impossible to get rid of bottleneck if you use a single websocket for all of the game. I am now trying to use a websocket per match. I increased the 16ms to 40ms fps rate which client sends update functions. I am now able to run the game with 10 players sending 50 bit of messages 40ms each.
I have though of many things like spawning a websocket module for each player or many other things. But the cleanest thing i think is to use a single websocket per every match and make it possible to play every player with 40 - 100 ms delay.