[Erlang32]ibrowse流程及性能測試

1.簡介

ibrowse是用erlang寫的一個HTTP client.github地址:https://github.com/cmullaparthi/ibrowse 使用方法見項目的readme。

2.流程

ibrowse:start ---> 爲每一個{host,port}創建一個ibrowse_lb的gen_server進程,用於管理此{host, port}下的連接狀態。

它會根據配置中的maxsession創建ibrowse_http_client的work(:gen_server)是用來創建實際的連接。每個work可以同時處理maxpipe個連接。

如果你不在priv/ibrowse.conf 裏面配置,max_sessions max_pipe_size都是10,如果想大併發使用,請務必根據實際情況測試,然後選擇適當的參數。

它有自己的負載均衡(load balance)機制:用Orderedi set ets ibrowse_lb優選進程中的每個session同時處理的連接數中最少的session。

如果你不想使用load balance機制:你可以使用

ibrowse:start_worker_process/1
ibrowse:send_req_direct/4,5,6,7,
ibrowse:stop_work_process/1

來自己管理負載。

3.性能測試

可以使用https://github.com/talko/httpcbench 來對erlang寫的這幾個主流HTTP client做下測試。

最好把裏面的http請求都改成自己實際的請求地址。

4.配置說明

%%priv/ibroswer.conf
{dest,HostName1,Portnumber1,MaxSessions,MaxPipelineSize,Options}
{dest,HostName2,Portnumber2,MaxSessions,MaxPipelineSize,Options}

    

4.1 爲每一對{Host,Port}最多創建MaxSessions;
4.2 每個session最多可同時處理MaxPipeLineSize;
4.3 如果所有的session都達到了Max,就會返回重試三次後返回{error,try_later};
4.4 Options爲connect網絡參數。可見文檔:
%% optionList() = [option()]
%% option() = {max_sessions, integer()}        |
%%          {response_format,response_format()}|
%%          {stream_chunk_size, integer()}     |
%%          {max_pipeline_size, integer()}     |
%%          {trace, boolean()}                 | 
%%          {is_ssl, boolean()}                |
%%          {ssl_options, [SSLOpt]}            |
%%          {pool_name, atom()}                |
%%          {proxy_host, string()}             |
%%          {proxy_port, integer()}            |
%%          {proxy_user, string()}             |
%%          {proxy_password, string()}         |
%%          {use_absolute_uri, boolean()}      |
%%          {basic_auth, {username(), password()}} |
%%          {cookie, string()}                 |
%%          {content_length, integer()}        |
%%          {content_type, string()}           |
%%          {save_response_to_file, srtf()}    |
%%          {stream_to, stream_to()}           |
%%          {http_vsn, {MajorVsn, MinorVsn}}   |
%%          {host_header, string()}            |
%%          {inactivity_timeout, integer()}    |
%%          {connect_timeout, integer()}       |
%%          {socket_options, Sock_opts}        |
%%          {transfer_encoding, {chunked, ChunkSize}} | 
%%          {headers_as_is, boolean()}         |
%%          {give_raw_headers, boolean()}      |
%%          {preserve_chunked_encoding,boolean()}     |
%%          {workaround, head_response_with_body}     |
%%          {worker_process_options, list()}
%%
%% stream_to() = process() | {process(), once}
%% process() = pid() | atom()
%% username() = string()
%% password() = string()
%% SSLOpt = term()
%% Sock_opts = [Sock_opt]
%% Sock_opt = term()
%% ChunkSize = integer()
%% srtf() = boolean() | filename() | {append, filename()}
%% filename() = string()
%% response_format() = list | binary
View Code

流程圖可見:https://github.com/zhongwencool/issue_blog/tree/master/freemind  使用freemind記錄。

 

first try SSL using Erlang

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章