diff --git a/include/agHttpCli.hrl b/include/agHttpCli.hrl index 203697b..c8a3ec9 100644 --- a/include/agHttpCli.hrl +++ b/include/agHttpCli.hrl @@ -17,7 +17,7 @@ -define(DEFAULT_RECONNECT_MAX, 120000). -define(DEFAULT_TIMEOUT, infinity). -define(DEFAULT_PID, self()). --define(DEFAULT_SOCKET_OPTS, [binary, {active, true}, {delay_send, true}, {nodelay, true}, {keepalive, true}, {recbuf, 1048576}, {send_timeout, 5000}, {send_timeout_close, true}]). +-define(DEFAULT_SOCKET_OPTS, [binary, {active, true}, {nodelay, true}, {delay_send, true}, {keepalive, true}, {recbuf, 2097152}, {send_timeout, 5000}, {send_timeout_close, true}]). -define(GET_FROM_LIST(Key, List), agMiscUtils:getListValue(Key, List, undefined)). -define(GET_FROM_LIST(Key, List, Default), agMiscUtils:getListValue(Key, List, Default)). diff --git a/src/arangoApi/agAdminMonitor.erl b/src/arangoApi/agAdminMonitor.erl index 9bf86e9..3d07674 100644 --- a/src/arangoApi/agAdminMonitor.erl +++ b/src/arangoApi/agAdminMonitor.erl @@ -1,6 +1,8 @@ -module(agAdminMonitor). -include("erlArango.hrl"). +-compile(inline). +-compile({inline_size, 128}). -compile([export_all, nowarn_export_all]). % doc_address:https://www.arangodb.com/docs/stable/http/administration-and-monitoring.html diff --git a/src/arangoApi/agAnalyzers.erl b/src/arangoApi/agAnalyzers.erl index 08c57b6..cf28a6c 100644 --- a/src/arangoApi/agAnalyzers.erl +++ b/src/arangoApi/agAnalyzers.erl @@ -1,6 +1,8 @@ -module(agAnalyzers). -include("erlArango.hrl"). +-compile(inline). +-compile({inline_size, 128}). -compile([export_all, nowarn_export_all]). % doc_address:https://www.arangodb.com/docs/stable/http/analyzers.html diff --git a/src/arangoApi/agAqlMod.erl b/src/arangoApi/agAqlMod.erl index 4b517dc..404dd9c 100644 --- a/src/arangoApi/agAqlMod.erl +++ b/src/arangoApi/agAqlMod.erl @@ -1,6 +1,8 @@ -module(agAqlMod). -include("erlArango.hrl"). +-compile(inline). +-compile({inline_size, 128}). -compile([export_all, nowarn_export_all]). % doc_address: diff --git a/src/arangoApi/agAsyncResultHandling.erl b/src/arangoApi/agAsyncResultHandling.erl index a8069f1..8c6dbe7 100644 --- a/src/arangoApi/agAsyncResultHandling.erl +++ b/src/arangoApi/agAsyncResultHandling.erl @@ -1,6 +1,8 @@ -module(agAsyncResultHandling). -include("erlArango.hrl"). +-compile(inline). +-compile({inline_size, 128}). -compile([export_all, nowarn_export_all]). % doc_address:https://www.arangodb.com/docs/stable/http/async-results-management.html diff --git a/src/arangoApi/agBulkImportExport.erl b/src/arangoApi/agBulkImportExport.erl index c59929d..8dc3311 100644 --- a/src/arangoApi/agBulkImportExport.erl +++ b/src/arangoApi/agBulkImportExport.erl @@ -1,6 +1,8 @@ -module(agBulkImportExport). -include("erlArango.hrl"). +-compile(inline). +-compile({inline_size, 128}). -compile([export_all, nowarn_export_all]). % doc_address:https://www.arangodb.com/docs/stable/http/bulk-imports.html diff --git a/src/arangoApi/agCluster.erl b/src/arangoApi/agCluster.erl index 1225e92..bdd1966 100644 --- a/src/arangoApi/agCluster.erl +++ b/src/arangoApi/agCluster.erl @@ -1,6 +1,8 @@ -module(agCluster). -include("erlArango.hrl"). +-compile(inline). +-compile({inline_size, 128}). -compile([export_all, nowarn_export_all]). %% doc_address:https://www.arangodb.com/docs/stable/http/cluster.html diff --git a/src/arangoApi/agCollections.erl b/src/arangoApi/agCollections.erl index 7036d7a..7f8e251 100644 --- a/src/arangoApi/agCollections.erl +++ b/src/arangoApi/agCollections.erl @@ -1,6 +1,8 @@ -module(agCollections). -include("erlArango.hrl"). +-compile(inline). +-compile({inline_size, 128}). -compile([export_all, nowarn_export_all]). % doc_address:https://www.arangodb.com/docs/stable/http/collection.html diff --git a/src/arangoApi/agDbMgr.erl b/src/arangoApi/agDbMgr.erl index c54a80f..ca03cd1 100644 --- a/src/arangoApi/agDbMgr.erl +++ b/src/arangoApi/agDbMgr.erl @@ -1,6 +1,8 @@ -module(agDbMgr). -include("erlArango.hrl"). +-compile(inline). +-compile({inline_size, 128}). -compile([export_all, nowarn_export_all]). %% doc_address:https://www.arangodb.com/docs/stable/http/database-database-management.html diff --git a/src/arangoApi/agDocuments.erl b/src/arangoApi/agDocuments.erl index a4515a8..b17b3b9 100644 --- a/src/arangoApi/agDocuments.erl +++ b/src/arangoApi/agDocuments.erl @@ -1,6 +1,8 @@ -module(agDocuments). -include("erlArango.hrl"). +-compile(inline). +-compile({inline_size, 128}). -compile([export_all, nowarn_export_all]). %% doc_address:https://www.arangodb.com/docs/stable/http/document.html diff --git a/src/arangoApi/agEdges.erl b/src/arangoApi/agEdges.erl index 13a7068..82f4a3b 100644 --- a/src/arangoApi/agEdges.erl +++ b/src/arangoApi/agEdges.erl @@ -1,6 +1,8 @@ -module(agEdges). -include("erlArango.hrl"). +-compile(inline). +-compile({inline_size, 128}). -compile([export_all, nowarn_export_all]). %% doc_address:https://www.arangodb.com/docs/stable/http/edge.html diff --git a/src/arangoApi/agEndPoints.erl b/src/arangoApi/agEndPoints.erl index f29a663..bb7c619 100644 --- a/src/arangoApi/agEndPoints.erl +++ b/src/arangoApi/agEndPoints.erl @@ -1,6 +1,8 @@ -module(agEndPoints). -include("erlArango.hrl"). +-compile(inline). +-compile({inline_size, 128}). -compile([export_all, nowarn_export_all]). % doc_address:https://www.arangodb.com/docs/stable/http/endpoints.html diff --git a/src/arangoApi/agFoxxServices.erl b/src/arangoApi/agFoxxServices.erl index 64c98ed..458ddfc 100644 --- a/src/arangoApi/agFoxxServices.erl +++ b/src/arangoApi/agFoxxServices.erl @@ -1,6 +1,8 @@ -module(agFoxxServices). -include("erlArango.hrl"). +-compile(inline). +-compile({inline_size, 128}). -compile([export_all, nowarn_export_all]). % doc_address:https://www.arangodb.com/docs/stable/http/foxx.html diff --git a/src/arangoApi/agGeneralGraphs.erl b/src/arangoApi/agGeneralGraphs.erl index 77a9dec..d90f83b 100644 --- a/src/arangoApi/agGeneralGraphs.erl +++ b/src/arangoApi/agGeneralGraphs.erl @@ -1,6 +1,8 @@ -module(agGeneralGraphs). -include("erlArango.hrl"). +-compile(inline). +-compile({inline_size, 128}). -compile([export_all, nowarn_export_all]). %% doc_address:https://www.arangodb.com/docs/stable/http/gharial.html diff --git a/src/arangoApi/agHotBackup.erl b/src/arangoApi/agHotBackup.erl index a2858d6..31b5e71 100644 --- a/src/arangoApi/agHotBackup.erl +++ b/src/arangoApi/agHotBackup.erl @@ -1,6 +1,8 @@ -module(agHotBackup). -include("erlArango.hrl"). +-compile(inline). +-compile({inline_size, 128}). -compile([export_all, nowarn_export_all]). % doc_address:https://www.arangodb.com/docs/stable/http/hot-backup.html diff --git a/src/arangoApi/agIndexes.erl b/src/arangoApi/agIndexes.erl index 37a3a02..0d84755 100644 --- a/src/arangoApi/agIndexes.erl +++ b/src/arangoApi/agIndexes.erl @@ -1,6 +1,8 @@ -module(agIndexes). -include("erlArango.hrl"). +-compile(inline). +-compile({inline_size, 128}). -compile([export_all, nowarn_export_all]). % doc_address:https://www.arangodb.com/docs/stable/http/indexes.html diff --git a/src/arangoApi/agMiscFun.erl b/src/arangoApi/agMiscFun.erl index f6fec3f..8750e73 100644 --- a/src/arangoApi/agMiscFun.erl +++ b/src/arangoApi/agMiscFun.erl @@ -1,6 +1,8 @@ -module(agMiscFun). -include("erlArango.hrl"). +-compile(inline). +-compile({inline_size, 128}). -compile([export_all, nowarn_export_all]). %% doc_address:https://www.arangodb.com/docs/stable/http/miscellaneous-functions.html diff --git a/src/arangoApi/agRepairJobs.erl b/src/arangoApi/agRepairJobs.erl index c5f8e3c..193d3dc 100644 --- a/src/arangoApi/agRepairJobs.erl +++ b/src/arangoApi/agRepairJobs.erl @@ -1,6 +1,8 @@ -module(agRepairJobs). -include("erlArango.hrl"). +-compile(inline). +-compile({inline_size, 128}). -compile([export_all, nowarn_export_all]). %% doc_address:https://www.arangodb.com/docs/stable/http/repairs.html diff --git a/src/arangoApi/agReplication.erl b/src/arangoApi/agReplication.erl index 18cd18a..269159f 100644 --- a/src/arangoApi/agReplication.erl +++ b/src/arangoApi/agReplication.erl @@ -1,6 +1,8 @@ -module(agReplication). -include("erlArango.hrl"). +-compile(inline). +-compile({inline_size, 128}). -compile([export_all, nowarn_export_all]). % doc_address:https://www.arangodb.com/docs/3.6/http/replications.html diff --git a/src/arangoApi/agSimpleQueries.erl b/src/arangoApi/agSimpleQueries.erl index 8869b5f..450073f 100644 --- a/src/arangoApi/agSimpleQueries.erl +++ b/src/arangoApi/agSimpleQueries.erl @@ -1,6 +1,8 @@ -module(agSimpleQueries). -include("erlArango.hrl"). +-compile(inline). +-compile({inline_size, 128}). -compile([export_all, nowarn_export_all]). % doc_address:https://www.arangodb.com/docs/stable/http/simple-query.html diff --git a/src/arangoApi/agTasks.erl b/src/arangoApi/agTasks.erl index 5391c27..bc7cb45 100644 --- a/src/arangoApi/agTasks.erl +++ b/src/arangoApi/agTasks.erl @@ -1,6 +1,8 @@ -module(agTasks). -include("erlArango.hrl"). +-compile(inline). +-compile({inline_size, 128}). -compile([export_all, nowarn_export_all]). % doc_address:https://www.arangodb.com/docs/stable/http/traversal.html diff --git a/src/arangoApi/agTransactions.erl b/src/arangoApi/agTransactions.erl index b34471a..7e7b130 100644 --- a/src/arangoApi/agTransactions.erl +++ b/src/arangoApi/agTransactions.erl @@ -1,6 +1,8 @@ -module(agTransactions). -include("erlArango.hrl"). +-compile(inline). +-compile({inline_size, 128}). -compile([export_all, nowarn_export_all]). % doc_address:https://www.arangodb.com/docs/stable/http/transaction.html diff --git a/src/arangoApi/agTraversals.erl b/src/arangoApi/agTraversals.erl index 31ee36c..1e5d0ad 100644 --- a/src/arangoApi/agTraversals.erl +++ b/src/arangoApi/agTraversals.erl @@ -1,6 +1,8 @@ -module(agTraversals). -include("erlArango.hrl"). +-compile(inline). +-compile({inline_size, 128}). -compile([export_all, nowarn_export_all]). % doc_address:https://www.arangodb.com/docs/stable/http/traversal.html diff --git a/src/arangoApi/agUserMgr.erl b/src/arangoApi/agUserMgr.erl index b44dc17..cffd1d9 100644 --- a/src/arangoApi/agUserMgr.erl +++ b/src/arangoApi/agUserMgr.erl @@ -1,6 +1,8 @@ -module(agUserMgr). -include("erlArango.hrl"). +-compile(inline). +-compile({inline_size, 128}). -compile([export_all, nowarn_export_all]). % doc_address:https://www.arangodb.com/docs/stable/http/user-management.html diff --git a/src/arangoApi/agViews.erl b/src/arangoApi/agViews.erl index 63e8a8c..b3a852a 100644 --- a/src/arangoApi/agViews.erl +++ b/src/arangoApi/agViews.erl @@ -1,6 +1,8 @@ -module(agViews). -include("erlArango.hrl"). +-compile(inline). +-compile({inline_size, 128}). -compile([export_all, nowarn_export_all]). % doc_address:https://www.arangodb.com/docs/stable/http/views.html diff --git a/src/httpCli/agAgencyPoolMgrIns.erl b/src/httpCli/agAgencyPoolMgrIns.erl index f361fc7..95efec2 100644 --- a/src/httpCli/agAgencyPoolMgrIns.erl +++ b/src/httpCli/agAgencyPoolMgrIns.erl @@ -112,7 +112,7 @@ agencyMod(_) -> agencySpec(ServerMod, ServerName, Args) -> %% TODO 下面spawn_opt 参数需要调优 - StartFunc = {ServerMod, start_link, [ServerName, Args, [{min_heap_size, 5000}, {min_bin_vheap_size, 100000}, {fullsweep_after, 500}]]}, + StartFunc = {ServerMod, start_link, [ServerName, Args, [{min_heap_size, 10240}, {min_bin_vheap_size, 524288}, {fullsweep_after, 512}]]}, {ServerName, StartFunc, transient, infinity, worker, [ServerMod]}. -spec startChildren(atom(), protocol(), poolSize(), agencyOpts()) -> ok. diff --git a/src/httpCli/agHttpCli.erl b/src/httpCli/agHttpCli.erl index f1036cc..aed19cb 100644 --- a/src/httpCli/agHttpCli.erl +++ b/src/httpCli/agHttpCli.erl @@ -14,7 +14,7 @@ , castAgency/6 , castAgency/7 , castAgency/8 - , receiveResponse/2 + , receiveRequestRet/2 %% 连接池API , startPool/2 @@ -41,7 +41,7 @@ callAgency(PoolNameOrSocket, Method, Path, Headers, Body, IsSystem) -> callAgency(PoolNameOrSocket, Method, Path, Headers, Body, IsSystem, Timeout) -> case castAgency(PoolNameOrSocket, Method, Path, Headers, Body, self(), IsSystem, Timeout) of {ok, RequestId, MonitorRef} -> - receiveResponse(RequestId, MonitorRef); + receiveRequestRet(RequestId, MonitorRef); {error, _Reason} = Err -> Err; Ret -> @@ -124,14 +124,14 @@ castAgency(PoolNameOrSocket, Method, Path, Headers, Body, Pid, IsSystem, Timeout end end. --spec receiveResponse(requestId(), reference()) -> term() | {error, term()}. -receiveResponse(RequestId, MonitorRef) -> +-spec receiveRequestRet(requestId(), reference()) -> term() | {error, term()}. +receiveRequestRet(RequestId, MonitorRef) -> receive #miRequestRet{requestId = RequestId, reply = Reply} -> erlang:demonitor(MonitorRef), case Reply of {ok, Headers, Body} -> - {ok, Headers, jiffy:decode(Body, [return_maps])}; + {ok, Headers, jiffy:decode(Body, [return_maps, copy_strings])}; _ -> Reply end; @@ -145,7 +145,7 @@ receiveTcpData(RecvState, Socket, TimerRef, Rn, RnRn, IsHeadMethod) -> {tcp, Socket, Data} -> try agHttpProtocol:response(RecvState, Rn, RnRn, Data, IsHeadMethod) of {done, #recvState{headers = Headers, body = Body}} -> - {ok, Headers, jiffy:decode(Body, [return_maps])}; + {ok, Headers, jiffy:decode(Body, [return_maps, copy_strings])}; {ok, NewRecvState} -> receiveTcpData(NewRecvState, Socket, TimerRef, Rn, RnRn, IsHeadMethod); {error, Reason} -> @@ -165,10 +165,7 @@ receiveTcpData(RecvState, Socket, TimerRef, Rn, RnRn, IsHeadMethod) -> {error, tcp_closed}; {tcp_error, Socket, Reason} -> disConnectDb(Socket), - {error, {tcp_error, Reason}}; - _Msg -> - ?WARN(receiveTcpData, "receive unexpect msg: ~p~n", [_Msg]), - receiveTcpData(RecvState, Socket, TimerRef, Rn, RnRn, IsHeadMethod) + {error, {tcp_error, Reason}} end. -spec receiveSslData(recvState() | undefined, socket(), reference() | undefined, binary:cp(), binary:cp(), boolean()) -> {ok, term(), term()} | {error, term()}. @@ -177,9 +174,9 @@ receiveSslData(RecvState, Socket, TimerRef, Rn, RnRn, IsHeadMethod) -> {ssl, Socket, Data} -> try agHttpProtocol:response(RecvState, Rn, RnRn, Data, IsHeadMethod) of {done, #recvState{headers = Headers, body = Body}} -> - {ok, Headers, jiffy:decode(Body, [return_maps])}; + {ok, Headers, jiffy:decode(Body, [return_maps, copy_strings])}; {ok, NewRecvState} -> - receiveTcpData(NewRecvState, Socket, TimerRef, Rn, RnRn, IsHeadMethod); + receiveSslData(NewRecvState, Socket, TimerRef, Rn, RnRn, IsHeadMethod); {error, Reason} -> ?WARN(receiveSslData, "handle tcp data error: ~p ~n", [Reason]), disConnectDb(Socket), @@ -197,10 +194,7 @@ receiveSslData(RecvState, Socket, TimerRef, Rn, RnRn, IsHeadMethod) -> {error, ssl_closed}; {ssl_error, Socket, Reason} -> disConnectDb(Socket), - {error, {ssl_error, Reason}}; - _Msg -> - ?WARN(receiveSslData, "receive unexpect msg: ~p~n", [_Msg]), - receiveSslData(RecvState, Socket, TimerRef, Rn, RnRn, IsHeadMethod) + {error, {ssl_error, Reason}} end. -spec startPool(poolName(), dbCfgs()) -> ok | {error, pool_name_used}. diff --git a/src/httpCli/agHttpProtocol.erl b/src/httpCli/agHttpProtocol.erl index 8977d9b..c0c5f1b 100644 --- a/src/httpCli/agHttpProtocol.erl +++ b/src/httpCli/agHttpProtocol.erl @@ -59,7 +59,7 @@ response(undefined, Rn, RnRn, Data, IsHeadMethod) -> {chunked, Headers, Body} -> case IsHeadMethod orelse StatusCode == 204 orelse StatusCode == 304 orelse (StatusCode < 200 andalso StatusCode >= 100) of true -> - {done, #recvState{stage = done, statusCode = StatusCode, headers = Headers, contentLength = 0, body = Rest}}; + {done, #recvState{stage = done, statusCode = StatusCode, headers = Headers, contentLength = 0, body = <<"{}">>}}; _ -> RecvState = #recvState{stage = body, contentLength = chunked, statusCode = StatusCode, headers = Headers}, response(RecvState, Rn, RnRn, Body, IsHeadMethod) @@ -75,7 +75,7 @@ response(undefined, Rn, RnRn, Data, IsHeadMethod) -> true -> case IsHeadMethod orelse StatusCode == 204 orelse StatusCode == 304 orelse (StatusCode < 200 andalso StatusCode >= 100) of true -> - {done, #recvState{stage = done, statusCode = StatusCode, headers = Headers, contentLength = ContentLength, body = Body}}; + {done, #recvState{stage = done, statusCode = StatusCode, headers = Headers, contentLength = ContentLength, body = <<"{}">>}}; _ -> {ok, #recvState{stage = body, statusCode = StatusCode, headers = Headers, contentLength = ContentLength, body = Body}} end @@ -126,7 +126,7 @@ response(#recvState{stage = header, body = OldBody}, Rn, RnRn, Data, IsHeadMetho {chunked, Headers, Rest} -> case IsHeadMethod orelse StatusCode == 204 orelse StatusCode == 304 orelse (StatusCode < 200 andalso StatusCode >= 100) of true -> - {done, #recvState{stage = done, statusCode = StatusCode, headers = Headers, contentLength = 0, body = Rest}}; + {done, #recvState{stage = done, statusCode = StatusCode, headers = Headers, contentLength = 0, body = <<"{}">>}}; _ -> RecvState = #recvState{stage = body, contentLength = chunked, statusCode = StatusCode, headers = Headers}, response(RecvState, Rn, RnRn, Rest, IsHeadMethod) @@ -142,7 +142,7 @@ response(#recvState{stage = header, body = OldBody}, Rn, RnRn, Data, IsHeadMetho true -> case IsHeadMethod orelse StatusCode == 204 orelse StatusCode == 304 orelse (StatusCode < 200 andalso StatusCode >= 100) of true -> - {done, #recvState{stage = done, statusCode = StatusCode, headers = Headers, contentLength = ContentLength, body = Body}}; + {done, #recvState{stage = done, statusCode = StatusCode, headers = Headers, contentLength = ContentLength, body = <<"{}">>}}; _ -> {ok, #recvState{stage = body, statusCode = StatusCode, headers = Headers, contentLength = ContentLength, body = Body}} end @@ -167,7 +167,7 @@ splitHeaders(Data, Rn, RnRn) -> [Headers, Body] -> HeadersList = binary:split(Headers, Rn, [global]), ContentLength = contentLength(HeadersList), - {ContentLength, HeadersList, Body} + {ContentLength, Headers, Body} end. contentLength([]) -> diff --git a/src/httpCli/agMiscUtils.erl b/src/httpCli/agMiscUtils.erl index c85594e..70a2863 100644 --- a/src/httpCli/agMiscUtils.erl +++ b/src/httpCli/agMiscUtils.erl @@ -13,6 +13,7 @@ , randomElement/1 , toBinary/1 , spellQueryPars/1 + , getHeaderValue/2 , lookHeader/2 ]). @@ -107,9 +108,14 @@ spellQueryPars([{Key, Value} | Tail]) -> TailBinary = <<<<"&", (toBinary(OtherKey))/binary, "=", (toBinary(OtherValue))/binary>> || {OtherKey, OtherValue} <- Tail>>, <>. +-spec getHeaderValue(binary(), binary()) -> binary(). +getHeaderValue(Header, HeaderBin) -> + HeadersList = binary:split(HeaderBin, <<"\r\n">>, [global]), + lookHeader(Header, HeadersList). + -spec lookHeader(binary, list()) -> binary(). lookHeader(_Header, []) -> - <<>>; + undefined; lookHeader(Header, [H | T]) -> case binary:split(H, <<": ">>) of [Header, Value] -> diff --git a/src/httpCli/agSslAgencyIns.erl b/src/httpCli/agSslAgencyIns.erl index 26be99e..dd35516 100644 --- a/src/httpCli/agSslAgencyIns.erl +++ b/src/httpCli/agSslAgencyIns.erl @@ -188,7 +188,7 @@ overDealQueueRequest(#miRequest{method = Method, path = Path, headers = Headers, -spec overReceiveSslData(srvState(), cliState()) -> {ok, srvState(), cliState()}. overReceiveSslData(#srvState{poolName = PoolName, serverName = ServerName, rn = Rn, rnrn = RnRn, socket = Socket} = SrvState, - #cliState{isHeadMethod = IsHeadMethod, backlogNum = BacklogNum, curInfo = CurInfo, requestsOut = RequestsOut, recvState = RecvState} = CliState) -> + #cliState{isHeadMethod = IsHeadMethod, backlogNum = BacklogNum, curInfo = CurInfo, requestsIn = RequestsIn, requestsOut = RequestsOut, recvState = RecvState} = CliState) -> receive {ssl, Socket, Data} -> try agHttpProtocol:response(RecvState, Rn, RnRn, Data, IsHeadMethod) of @@ -245,6 +245,9 @@ overReceiveSslData(#srvState{poolName = PoolName, serverName = ServerName, rn = {ssl_error, Socket, Reason} -> ssl:close(Socket), agAgencyUtils:dealClose(SrvState, CliState, {error, {ssl_error, Reason}}); + #miRequest{} = MiRequest -> + agAgencyUtils:addQueue(RequestsIn, MiRequest), + overReceiveSslData(SrvState, CliState#cliState{requestsIn = RequestsIn + 1, backlogNum = BacklogNum + 1}); _Msg -> ?WARN(overReceiveSslData, "receive unexpect msg: ~p~n", [_Msg]), overReceiveSslData(SrvState, CliState) diff --git a/src/httpCli/agTcpAgencyIns.erl b/src/httpCli/agTcpAgencyIns.erl index e2ce751..64e6de2 100644 --- a/src/httpCli/agTcpAgencyIns.erl +++ b/src/httpCli/agTcpAgencyIns.erl @@ -187,7 +187,7 @@ overDealQueueRequest(#miRequest{method = Method, path = Path, headers = Headers, -spec overReceiveTcpData(srvState(), cliState()) -> {ok, srvState(), cliState()}. overReceiveTcpData(#srvState{poolName = PoolName, serverName = ServerName, rn = Rn, rnrn = RnRn, socket = Socket} = SrvState, - #cliState{isHeadMethod = IsHeadMethod, backlogNum = BacklogNum, curInfo = CurInfo, requestsOut = RequestsOut, recvState = RecvState} = CliState) -> + #cliState{isHeadMethod = IsHeadMethod, backlogNum = BacklogNum, curInfo = CurInfo, requestsIn = RequestsIn, requestsOut = RequestsOut, recvState = RecvState} = CliState) -> receive {tcp, Socket, Data} -> try agHttpProtocol:response(RecvState, Rn, RnRn, Data, IsHeadMethod) of @@ -244,6 +244,9 @@ overReceiveTcpData(#srvState{poolName = PoolName, serverName = ServerName, rn = {tcp_error, Socket, Reason} -> gen_tcp:close(Socket), agAgencyUtils:dealClose(SrvState, CliState, {error, {tcp_error, Reason}}); + #miRequest{} = MiRequest -> + agAgencyUtils:addQueue(RequestsIn, MiRequest), + overReceiveTcpData(SrvState, CliState#cliState{requestsIn = RequestsIn + 1, backlogNum = BacklogNum + 1}); _Msg -> ?WARN(overReceiveTcpData, "receive unexpect msg: ~p~n", [_Msg]), overReceiveTcpData(SrvState, CliState) diff --git a/src/user_default.erl b/src/user_default.erl index b90c96c..a366c8e 100644 --- a/src/user_default.erl +++ b/src/user_default.erl @@ -10,23 +10,21 @@ start() -> agHttpCli:startPool(tt, [{poolSize, 10}], []). tt(C, N) -> - application:start(erlArango), - agHttpCli:startPool(tt, [{poolSize, 100}], []), - Request = {<<"GET">>, <<"/_api/database/current">>, [], []}, - io:format("IMY********************** start time ~p~n", [erlang:system_time(millisecond)]), - [spawn(test, test, [N, Request]) || _Idx <- lists:seq(1, C)]. + application:ensure_all_started(erlArango), + agHttpCli:startPool(tt, [{poolSize, 16}], []), + StartTime = erlang:system_time(millisecond), + io:format("IMY********************** started~n"), + [spawn(?MODULE, test, [N, StartTime]) || _Idx <- lists:seq(1, C)]. %%test(N, Request). %% /_api/database -test(0, Request) -> - R1 = {<<"GET">>, <<"/_api/database">>, [], []}, - agHttpCli:callAgency(tt, R1, 5000), - io:format("IMY********************** test over ~p~n", [erlang:system_time(millisecond)]); -test(N, Request) -> - erlang:put(cnt, N), - agHttpCli:callAgency(tt, Request, 5000), - test(N - 1, Request). +test(0, StartTime) -> + agDbMgr:curDbList(tt), + io:format("IMY******test over use time ~p~n", [erlang:system_time(millisecond) - StartTime]); +test(N, StartTime) -> + agDbMgr:curDbList(tt), + test(N - 1, StartTime). %% tt(C, N) -> %% application:start(erlArango), @@ -64,3 +62,96 @@ tcjx(N, Args1) -> Args = {[{name, ffd}, {tet, "fdsff"}, {<<"dfdf">>, 131245435346}]}, jiffy:encode(Args), tcjx(N - 1, Args1). + + + +-define(HeadBin, <<"X-Content-Type-Options: nosniff\r\nEtag: \"_aKwJ_tm--E\"\r\nServer: ArangoDB\r\nConnection: Keep-Alive\r\nContent-Type: application/json; charset=utf-8\r\nContent-Length: 178">>). +th1(0, Fun, Rn) -> + ?MODULE:Fun(?HeadBin, Rn); +th1(N, Fun, Rn) -> + ?MODULE:Fun(?HeadBin, Rn), + th1(N - 1, Fun, Rn). + +th2(0, Fun, Cl, Rn) -> + ?MODULE:Fun(?HeadBin, Cl, Rn); +th2(N, Fun, Cl, Rn) -> + ?MODULE:Fun(?HeadBin, Cl, Rn), + th2(N - 1, Fun, Cl, Rn). + +head1(Headers, Rn) -> + HeadersList = binary:split(Headers, Rn, [global]), + contentLength(HeadersList). + +head2(Headers, _Rn) -> + HeadersList = binary:split(Headers, <<"\r\n">>, [global]), + contentLength(HeadersList). + +head3(Headers, CL, Rn) -> + case binary:split(Headers, CL) of + [_, Rest1] -> + case binary:split(Rest1, Rn) of + [InBin, _Rest2] -> + binary_to_integer(InBin); + [InBin] -> + binary_to_integer(InBin) + end; + _ -> + 0 + end. + +%% binary:compile_pattern(<<"\r\n">>) +%% binary:compile_pattern(<<"Content-Length: ">>) + +head4(Headers, _CL, _Rn) -> + case binary:split(Headers, <<"Content-Length: ">>) of + [_, Rest1] -> + case binary:split(Rest1, <<"\r\n">>) of + [InBin, _Rest2] -> + binary_to_integer(InBin); + [InBin] -> + binary_to_integer(InBin) + end; + _ -> + 0 + end. + +contentLength([]) -> + undefined; +contentLength([<<"Content-Length: ", Rest/binary>> | _T]) -> + binary_to_integer(Rest); +contentLength([<<"content-length: ", Rest/binary>> | _T]) -> + binary_to_integer(Rest); +contentLength([<<"Transfer-Encoding: chunked">> | _T]) -> + chunked; +contentLength([<<"transfer-encoding: chunked">> | _T]) -> + chunked; +contentLength([_ | T]) -> + contentLength(T). + + +-define(BodyBin1, <<"{\"_key\":\"01J\",\"_id\":\"airports/01J\",\"_rev\":\"_aKwJ_tm--E\",\"name\":\"Hilliard Airpark\",\"city\":\"Hilliard\",\"state\":\"FL\",\"country\":\"USA\",\"lat\":30.6880125,\"long\":-81.90594389,\"vip\":false}">>). +-define(BodyBin2, <<"{\"_key\":\"01J\",\"_id\":\"airports/01J\",\"_rev\":\"_aPaBl7O--_\",\"name\":\"Hilliard Airpark\",\"city\":\"Hilliardfdfsdfdsffffffffffffffffffffffffffffffffffffffffffffffffffffffffafdsfasdfdafsdafdsfsdafdsafdsfdsfdsafdsfdsfdsfhghfghfghgfhsdsdfdsfdsfdsffdfddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddggggggggggggggggggggggggggggggggggggggggg\",\"state\":\"FL\",\"country\":\"USAjjkjkjkfgjkgjfkdjgldgjldjglfdjglfjdljljrlejtrltjewltjrelwtjrletjrletrletjlrejtjtrlwjrejwlrjjreljtljelwjrtlwjtreljrlewjrlwjrlwejrlejltkdfsafd\",\"lat\":30.6880125,\"long\":-81.90594389,\"vip\":false}">>). + +jd1(0, Fun) -> + ?MODULE:Fun(?BodyBin1); +jd1(N, Fun) -> + ?MODULE:Fun(?BodyBin1), + jd1(N - 1, Fun). + +jd2(0, Fun) -> + ?MODULE:Fun(?BodyBin2); +jd2(N, Fun) -> + ?MODULE:Fun(?BodyBin2), + jd2(N - 1, Fun). + +decode1(Bin) -> + jiffy:decode(Bin, [return_maps]). + +decode2(Bin) -> + jiffy:decode(Bin, [return_maps, copy_strings]). + +decode3(Bin) -> + jiffy:decode(Bin, [return_maps]). + +decode4(Bin) -> + jiffy:decode(Bin, [return_maps, copy_strings]).