shackle
0.6.20
Marco de cliente de red Erlang de alto rendimiento
- behavior ( shackle_client ).
- export ([
init / 0 ,
setup / 2 ,
handle_request / 2 ,
handle_data / 2 ,
terminate / 1
]).
- record ( state , {
buffer = <<>> :: binary (),
request_counter = 0 :: non_neg_integer ()
}).
- spec init ( Options :: term ()) ->
{ ok , State :: term ()} |
{ error , Reason :: term ()}.
init ( _Options ) ->
{ ok , # state {}}.
- spec setup ( Socket :: inet : socket (), State :: term ()) ->
{ ok , State :: term ()} |
{ error , Reason :: term (), State :: term ()}.
setup ( Socket , State ) ->
case gen_tcp : send ( Socket , << " INIT " >>) of
ok ->
case gen_tcp : recv ( Socket , 0 ) of
{ ok , << " OK " >>} ->
{ ok , State };
{ error , Reason } ->
{ error , Reason , State }
end ;
{ error , Reason } ->
{ error , Reason , State }
end .
- spec handle_request ( Request :: term (), State :: term ()) ->
{ ok , RequestId :: external_request_id (), Data :: iodata (), State :: term ()}.
handle_request ( noop , State ) ->
Data = arithmetic_protocol : request ( 0 , noop , 0 , 0 ),
{ ok , undefined , Data , State };
handle_request ({ Operation , A , B }, # state {
request_counter = RequestCounter
} = State ) ->
RequestId = request_id ( RequestCounter ),
Data = request ( RequestId , Operation , A , B ),
{ ok , RequestId , Data , State # state {
request_counter = RequestCounter + 1
}}.
- spec handle_data ( Data :: binary (), State :: term ()) ->
{ ok , [{ RequestId :: external_request_id (), Reply :: term ()}], State :: term ()}.
handle_data ( Data , # state {
buffer = Buffer
} = State ) ->
Data2 = << Buffer / binary , Data / binary >>,
{ Replies , Buffer2 } = parse_replies ( Data2 , []),
{ ok , Replies , State # state {
buffer = Buffer2
}}.
- spec terminate ( State :: term ()) -> ok .
terminate ( _State ) -> ok .
shackle_pool : start ( shackle_pool : name (), client (), client_options (), pool_options ())
Nombre | Tipo | Por defecto | Descripción |
---|---|---|---|
DIRECCIÓN | inet:dirección_ip() | inet:nombre de host() | "127.0.0.1" | dirección del servidor (anteriormente ip) |
puerto | inet:número_puerto() | indefinido | puerto del servidor |
protocolo | grillete_tcp | grillete_udp | grillete_ssl | grillete_tcp | protocolo del servidor |
reconectar | booleano() | verdadero | reconectar conexiones cerradas |
reconexión_tiempo_max | pos_entero() | infinidad | 120000 | tiempo máximo de reconexión en milisegundos |
reconexión_tiempo_min | pos_entero() | 1000 | tiempo mínimo de reconexión en milisegundos |
opciones_zócalo | [gen_tcp:connect_option() | gen_udp:opción()] | [] | opciones pasadas al socket |
Nombre | Tipo | Por defecto | Descripción |
---|---|---|---|
tamaño_atraso | pos_entero() | infinidad | 1024 | número máximo de solicitudes simultáneas por conexión |
max_retries | no_neg_integer() | 3 | Número máximo de intentos para encontrar un servidor activo. |
tamaño_piscina | pos_entero() | 16 | número de conexiones |
estrategia_piscina | aleatorio | round_robin | aleatorio | estrategia de selección de conexión |
1 > shackle : call ( pool_name , { get , << " test " >>}).
{ ok , << " bar " >>}
2 > { ok , ReqId } = shackle : cast ( pool_name , { get , << " foo " >>}, 500 ).
{ ok , { anchor , anchor_client , # Ref < 0.0 . 0.2407 > }}
3 > shackle : receive_response ( ReqId ).
{ ok , << " bar " >>}
Shackle se integra con la biblioteca de telemetría independiente del backend. Consulte shackle_telemetry
para obtener la lista de eventos de telemetría que puede emitir shackle.
make dialyzer
make eunit
make xref
Para ejecutar objetivos de prueba de rendimiento, primero debe iniciar el servidor:
./bin/server.sh
Luego puedes ejecutar el objetivo bench
o profile
:
make bench
make profile
Nombre | Descripción |
---|---|
ancla | Cliente Memcached |
nodo-aspike | Cliente Aerospike |
boya | Cliente HTTP 1.1 |
llamarada | Productor Kafka |
puerto pequeño | Cliente Cassandra CQL |
estadísticasderl | Cliente de estadísticas |
The MIT License (MIT)
Copyright (c) 2015-2023 Louis-Philippe Gauthier
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.