9
回答
erlang,大家看看,10w并发,我这样测试方法不正确么?
华为云实践训练营,热门技术免费实践!>>>   

这是服务端的代码,接收请求,处理数据:
----------------------------------------------------------------------------------------------------------

-module(t_server).
-export([start/0, start/1, wait_connect/1, response/1]).

-define(PORT, 8091).

start() -> start(?PORT).
start(Port) ->
    {ok, Lsocket} = gen_tcp:listen(Port, [binary, {active, false}, {reuseaddr, true}]),
    wait_connect(Lsocket).

wait_connect(Lsocket) ->
    {ok, Socket} = gen_tcp:accept(Lsocket),
    spawn(?MODULE, wait_connect, [Lsocket]),
    get_request(Socket, []).

get_request(Socket, BinaryList) ->
    case gen_tcp:recv(Socket, 0) of
        {ok, Binary} ->
            get_request(Socket, [Binary | BinaryList]);
        {error, closed} ->
            response(lists:reverse(BinaryList))
    end.

response(_Data) ->
    ok.




这是客户端的代码,就是发送一个链接,然后,发送过去一个数字而已:
----------------------------------------------------------------------------------------------------------

-module(t_server).
-export([start/0, start/1, wait_connect/1, response/1]).

-define(PORT, 8091).

start() -> start(?PORT).
start(Port) -> 
    {ok, Lsocket} = gen_tcp:listen(Port, [binary, {active, false}, {reuseaddr, true}]),
    wait_connect(Lsocket).

wait_connect(Lsocket) ->
    {ok, Socket} = gen_tcp:accept(Lsocket),
    spawn(?MODULE, wait_connect, [Lsocket]),
    get_request(Socket, []).

get_request(Socket, BinaryList) ->
    case gen_tcp:recv(Socket, 0) of
        {ok, Binary} ->
            get_request(Socket, [Binary | BinaryList]);
        {error, closed} ->
            response(lists:reverse(BinaryList))
    end.

response(_Data) ->
    ok.



这些配置:
ulimit -n 51200
ip_local_port_range 1024 61000
也设置过了,

现在 10万并发, 要7秒左右。

我机器配置是: 4核, I5-5320, 6G 内存, erlang 版本是 1603B
我测度过,除掉 socket连接,单单生成进程,100万,约1秒时间,但涉及 socket 慢了 10倍。。。

有加参数优化  -K true -S 4 -P 204800
问题出在了哪里了?

举报
顶部