Explorar el Código

注释修改

erlArango_http
maike hace 4 años
padre
commit
b532ae0c17
Se han modificado 9 ficheros con 46 adiciones y 54 borrados
  1. +30
    -28
      README.md
  2. +2
    -3
      rebar.config
  3. +3
    -8
      src/agHttpCli/agAgencyPoolMgrIns.erl
  4. +2
    -3
      src/agHttpCli/agAgencyUtils.erl
  5. +3
    -3
      src/agHttpCli/agHttpCli.erl
  6. +0
    -3
      src/agHttpCli/agHttpProtocol.erl
  7. +1
    -1
      src/agHttpCli/agKvsToBeam.erl
  8. +3
    -3
      src/agHttpCli/agSslAgencyIns.erl
  9. +2
    -2
      src/agHttpCli/agTcpAgencyIns.erl

+ 30
- 28
README.md Ver fichero

@ -1,39 +1,41 @@
# erlArango
arangodb多模数据库erlang驱动程序
arangodb erlang driver
erlang otp21.2+ arangodb 3.6.2 3.7
## 特点
高效,快速,简单易用。
1. 为了该驱动尽可能的高效,定制化封装了一个带连接池的http1.1的客户端(agHttpCli)
封装的agHttpCli与同类http客户端测试对比可参考:https://github.com/SisMaker/httpc_bench
2. 为了更加快速的decode和encode json数据,json库引入了jiffy,经过测试jiffy效率还是很不错的。
3. 该驱动可以使用连接池,也可以仅仅在单进程(非连接池模式)建立多个连接进行各种数据操作。使用连接池时支持同步与异步操作,如果要使用异步操作需要额外保存requestId
等待接收数据返回,当前改驱动封装的API均使用同步操作,如果需要异步操作可自行修改。单进程操作时仅支持同步操作。
单进程模式下相对连接池模式可以减少一次数据在进程间的复制,对于大量数据的操作,可以考虑在数据管理进程单独建立数据库连接,而不用连接池。
4. 连接池模式和非连接池模式API接口保证了同一性,不用区别对待, 易于理解和连接池模式和非连接池模式相互转换修改。
# Feature
Efficient, fast and easy to use.
1. To make this driver as efficient as possible, customizations encapsulate an HTTP1.1 client(agHttpCli) with connection pooling.
Comparisons between packaged agHttpCli and similar HTTP client tests are available:[Address](https://github.com/SisMaker/httpc_bench)
2. This driver can use connection pooling or simply establish multiple connections in a single process (non-connection pooling mode) for various data operations.
Synchronous and asynchronous operations are supported when using connection pooling,
and you need to save the requestId extra if you want to use asynchronous operations Waiting for the received data to return,
the API encapsulated by the current driver all USES synchronous operation, and can be modified if asynchronous operation is needed.
Only synchronous operations are supported for single-process operations.
In single-process mode, compared with connection pooling mode, data replication between processes can be reduced once.
For operation of large amount of data, database connection can be established separately in data management process instead of connection pooling.
3. The connection pooling mode and connectionless pool mode API interface ensures the identity, does not need to be treated differently,
and is easy to understand and change between connection pooling mode and connectionless pool mode.
## 暂不支持批处理请求
# Batch requests are not supported
https://www.arangodb.com/docs/stable/http/batch-request.html
## 编译
# compile
rebar get-deps; rebar compile or rebar3 compile
注意:在windows平台编译jiffy,需要额外搭建相关编译环境,具体可参见:https://github.com/SisMaker/erlUtils/tree/master/src/docs
## 使用
rebar: erl -pa ./ebin -pa ./deps/jiffy/ebin
Note: If you build Jiffy on The Windows platform, you will need to set up an additional compilation environment. [See jiffy for details](https://github.com/SisMaker/erlUtils/tree/master/src/docs)
# how to use
rebar: erl -pa ./ebin -pa ./deps/jiffy/ebin or
revar3: rebar3 shell
非连接池模式
先建立连接
{ok, S} = agHttpCli:connect([]). %% 使用默认的配置
然后就可以使用S作为第一个参数调用各种API了
Non-connection pooling mode
Make a connection first
{ok, Socket} = agHttpCli:connect([]). %% Use default Settings
Then you can then call various apis using Socket as the first argument
agMgrDb:curDbInfo(S).
连接池模式
application:ensure_all_started(erlArango). %%启动app
agHttpCli:startPool(poolName, [], []). %%初始连接池
然后就可以使用poolName作为第一个参数调用各种API了
Connection pooling mode
application:ensure_all_started(erlArango). %% start app
agHttpCli:startPool(poolName, [], []). %% start pool
Then you can then invoke various apis using poolName as the first argument
agMgrDb:curDbInfo(poolName).
## TODO
将注释转为edoc格式

+ 2
- 3
rebar.config Ver fichero

@ -1,8 +1,7 @@
{erl_opts, [{i, "include"}]}.
{edoc_opts, [{preprocess, true}]}.
{deps, [
{jiffy, {git, "https://github.com/davisp/jiffy.git", {tag, "1.0.5"}}},
%% {jsx, {git, "https://github.com/talentdeficit/jsx.git", {tag, "v3.0.0"}}},
{erlSync, ".*", {git, "https://github.com/SisMaker/erlSync.git", {branch, "master"}}}
{jiffy, {git, "https://github.com/davisp/jiffy.git", {tag, "1.0.5"}}}
%% {jsx, {git, "https://github.com/talentdeficit/jsx.git", {tag, "v3.0.0"}}}
]}.

+ 3
- 8
src/agHttpCli/agAgencyPoolMgrIns.erl Ver fichero

@ -16,15 +16,15 @@
, terminate/2
]).
%% k-v缓存表
%% k-v beam cache
-define(ETS_AG_Pool, ets_ag_Pool).
-define(ETS_AG_Agency, ets_ag_Agency).
%% TODO spawn_opt
%% TODO maybe spawn_opt params need optimize
-define(agencySpec(ServerMod, ServerName, Args),
#{
id => ServerName
, start => {ServerMod, start_link, [ServerName, Args, [{min_heap_size, 10240}, {min_bin_vheap_size, 524288}, {fullsweep_after, 1024}]]}
, start => {ServerMod, start_link, [ServerName, Args, [{min_heap_size, 10240}, {min_bin_vheap_size, 524288}, {fullsweep_after, 2048}]]}
, restart => transient
, shutdown => infinity
, type => worker
@ -120,11 +120,6 @@ agencyMod(ssl) ->
agencyMod(_) ->
agTcpAgencyExm.
%% agencySpec(ServerMod, ServerName, Args) ->
%% %% TODO spawn_opt
%% StartFunc = {ServerMod, start_link, [ServerName, Args, [{min_heap_size, 10240}, {min_bin_vheap_size, 524288}, {fullsweep_after, 1024}]]},
%% {ServerName, StartFunc, transient, infinity, worker, [ServerMod]}.
-spec startChildren(atom(), protocol(), poolSize(), agencyOpts()) -> ok.
startChildren(PoolName, Protocol, PoolSize, AgencyOpts) ->
AgencyMod = agencyMod(Protocol),

+ 2
- 3
src/agHttpCli/agAgencyUtils.erl Ver fichero

@ -59,16 +59,15 @@ cancelTimer(undefined) -> ok;
cancelTimer(TimerRef) ->
case erlang:cancel_timer(TimerRef) of
false ->
%%
receive
{timeout, TimerRef, _Msg} ->
%%
%% discard the timeout msg
ok
after 0 ->
ok
end;
_ ->
%% Timer
%% Timer already run
ok
end.

+ 3
- 3
src/agHttpCli/agHttpCli.erl Ver fichero

@ -6,7 +6,7 @@
-compile({inline_size, 128}).
-export([
%% API
%% Common Request API
callAgency/5
, callAgency/6
, callAgency/7
@ -16,12 +16,12 @@
, castAgency/8
, receiveRequestRet/2
%% API
%% Pools API
, startPool/2
, startPool/3
, stopPool/1
%% DbAPI
%% Single Process DbAPI
, connectDb/1
, disConnectDb/1
, getCurDbInfo/1

+ 0
- 3
src/agHttpCli/agHttpProtocol.erl Ver fichero

@ -81,11 +81,9 @@ response(undefined, Rn, RnRn, Data, IsHeadMethod) ->
end
end;
not_enough_data ->
%% headers都不足
{ok, #recvState{stage = header, body = Data}}
end;
not_enough_data ->
%% headers都不足
{ok, #recvState{stage = header, body = Data}};
{error, Reason} ->
{error, Reason}
@ -148,7 +146,6 @@ response(#recvState{stage = header, body = OldBody}, Rn, RnRn, Data, IsHeadMetho
end
end;
not_enough_data ->
%% headers都不足
{ok, #recvState{stage = header, body = CurBody}}
end;
not_enough_data ->

+ 1
- 1
src/agHttpCli/agKvsToBeam.erl Ver fichero

@ -7,7 +7,7 @@
load/2
]).
%% map类型的数据不能当做key
%% attention: the map type data can not as the key
-type key() :: atom() | binary() | bitstring() | float() | integer() | list() | tuple().
-type value() :: atom() | binary() | bitstring() | float() | integer() | list() | tuple() | map().

+ 3
- 3
src/agHttpCli/agSslAgencyIns.erl Ver fichero

@ -6,7 +6,7 @@
-compile({inline_size, 128}).
-export([
%% API
%% Inner Behavior API
init/1
, handleMsg/3
, terminate/3
@ -27,14 +27,14 @@ handleMsg(#miRequest{method = Method, path = Path, headers = Headers, body = Bod
agAgencyUtils:agencyReply(FromPid, RequestId, undefined, {error, noSocket}),
{ok, SrvState, CliState};
_ ->
case BacklogNum > BacklogSize of
case BacklogNum >= BacklogSize of
true ->
?WARN(ServerName, ":backlog full curNum:~p Total: ~p ~n", [BacklogNum, BacklogSize]),
agAgencyUtils:agencyReply(FromPid, RequestId, undefined, {error, backlogFull}),
{ok, SrvState, CliState};
_ ->
case Status of
leisure -> %%
leisure -> %%
Request = agHttpProtocol:request(IsSystem, Body, Method, Host, DbName, Path, [UserPassWord | Headers]),
case ssl:send(Socket, Request) of
ok ->

+ 2
- 2
src/agHttpCli/agTcpAgencyIns.erl Ver fichero

@ -6,7 +6,7 @@
-compile({inline_size, 128}).
-export([
%% API
%% Inner Behavior API
init/1
, handleMsg/3
, terminate/3
@ -27,7 +27,7 @@ handleMsg(#miRequest{method = Method, path = Path, headers = Headers, body = Bod
agAgencyUtils:agencyReply(FromPid, RequestId, undefined, {error, noSocket}),
{ok, SrvState, CliState};
_ ->
case BacklogNum > BacklogSize of
case BacklogNum >= BacklogSize of
true ->
?WARN(ServerName, ":backlog full curNum:~p Total: ~p ~n", [BacklogNum, BacklogSize]),
agAgencyUtils:agencyReply(FromPid, RequestId, undefined, {error, backlogFull}),

Cargando…
Cancelar
Guardar