All Projects → lpgauth → Shackle

lpgauth / Shackle

Licence: mit
High-Performance Erlang Network Client Framework

Programming Languages

erlang
1774 projects

Projects that are alternatives of or similar to Shackle

Socket
Non-blocking socket and TLS functionality for PHP based on Amp.
Stars: ✭ 122 (-25.15%)
Mutual labels:  tcp, udp, client
Netcat
💻 Netcat client and server modules written in pure Javascript for Node.js.
Stars: ✭ 315 (+93.25%)
Mutual labels:  tcp, udp, client
XAsyncSockets
XAsyncSockets is an efficient Python/MicroPython library of managed asynchronous sockets.
Stars: ✭ 28 (-82.82%)
Mutual labels:  ssl, tcp, udp
Qtswissarmyknife
QSAK (Qt Swiss Army Knife) is a multi-functional, cross-platform debugging tool based on Qt.
Stars: ✭ 196 (+20.25%)
Mutual labels:  tcp, udp, client
Zeus
A high performance, cross-platform Internet Communication Engine. Developed with native socket API. Aim at handling millions of concurrent connections.
Stars: ✭ 30 (-81.6%)
Mutual labels:  tcp, high-performance, client
Watsontcp
WatsonTcp is the easiest way to build TCP-based clients and servers in C#.
Stars: ✭ 209 (+28.22%)
Mutual labels:  tcp, ssl, client
ronin-support
A support library for Ronin. Like activesupport, but for hacking!
Stars: ✭ 23 (-85.89%)
Mutual labels:  ssl, tcp, udp
Asio2
Header only c++ network library, based on asio,support tcp,udp,http,websocket,rpc,ssl,icmp,serial_port.
Stars: ✭ 202 (+23.93%)
Mutual labels:  tcp, udp, ssl
Elixir Socket
Socket wrapping for Elixir.
Stars: ✭ 642 (+293.87%)
Mutual labels:  tcp, udp, ssl
Yasio
A multi-platform support c++11 library with focus on asio (asynchronous socket I/O) for any client application.
Stars: ✭ 483 (+196.32%)
Mutual labels:  tcp, udp, ssl
Swiddler
TCP/UDP debugging tool.
Stars: ✭ 56 (-65.64%)
Mutual labels:  ssl, tcp, udp
Packetsender
Network utility for sending / receiving TCP, UDP, SSL
Stars: ✭ 1,349 (+727.61%)
Mutual labels:  tcp, udp, ssl
Hp Socket
High Performance TCP/UDP/HTTP Communication Component
Stars: ✭ 4,420 (+2611.66%)
Mutual labels:  tcp, udp, ssl
Gensio
A library to abstract stream I/O like serial port, TCP, telnet, UDP, SSL, IPMI SOL, etc.
Stars: ✭ 30 (-81.6%)
Mutual labels:  tcp, udp, ssl
Simpletcp
Simple wrapper for TCP client and server in C# with SSL support
Stars: ✭ 99 (-39.26%)
Mutual labels:  tcp, ssl, client
Goproxy
🔥 Proxy is a high performance HTTP(S) proxies, SOCKS5 proxies,WEBSOCKET, TCP, UDP proxy server implemented by golang. Now, it supports chain-style proxies,nat forwarding in different lan,TCP/UDP port forwarding, SSH forwarding.Proxy是golang实现的高性能http,https,websocket,tcp,socks5代理服务器,支持内网穿透,链式代理,通讯加密,智能HTTP,SOCKS5代理,黑白名单,限速,限流量,限连接数,跨平台,KCP支持,认证API。
Stars: ✭ 11,334 (+6853.37%)
Mutual labels:  tcp, udp
Xtcp
A TCP Server Framework with graceful shutdown, custom protocol.
Stars: ✭ 116 (-28.83%)
Mutual labels:  framework, tcp
Gobetween
☁️ Modern & minimalistic load balancer for the Сloud era
Stars: ✭ 1,631 (+900.61%)
Mutual labels:  tcp, udp
Fi6s
IPv6 network scanner designed to be fast
Stars: ✭ 116 (-28.83%)
Mutual labels:  tcp, udp
Go Netstat
A netstat implementation written in Go
Stars: ✭ 121 (-25.77%)
Mutual labels:  tcp, udp

shackle

High-Performance Erlang Network Client Framework

Build Status

Requirements

  • Erlang 16.0+

Features

  • Backpressure via backlog (OOM protection)
  • Fast pool implementation (random, round_robin)
  • Managed timeouts
  • Multi-protocol support (SSL / TCP / UDP)
  • Performance-optimized
  • Request pipelining
  • Smart reconnect mechanism (exponential backoff)

Framework goals

  • Reusability
  • Speed
  • Concurrency
  • Safety

How-to

Implementing a client

-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.

Starting client pool

shackle_pool:start(pool_name(), client(), client_options(), pool_options())
client_options:
Name Type Default Description
address inet:ip_address() | inet:hostname() "127.0.0.1" server address (formerly ip)
port inet:port_number() undefined server port
protocol shackle_tcp | shackle_udp | shackle_ssl shackle_tcp server protocol
reconnect boolean() true reconnect closed connections
reconnect_time_max pos_integer() | infinity 120000 maximum reconnect time in milliseconds
reconnect_time_min pos_integer() 1000 minimum reconnect time in milliseconds
socket_options [gen_tcp:connect_option() | gen_udp:option()] [] options passed to the socket
pool_options:
Name Type Default Description
backlog_size pos_integer() | infinity 1024 maximum number of concurrent requests per connection
max_retries non_neg_integer() 3 maximum number of tries to find an active server
pool_size pos_integer() 16 number of connections
pool_strategy random | round_robin random connection selection strategy

Calling / Casting client

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">>}

Environment variables

Name Type Default Description
hooks [{atom(), {module(), atom()}}] [] used to receive events/metrics about your client

Hooks

Hooks allow you to receive events and metrics about your client. To do so you need to implement the shackle_hooks behaviour and then use the hooks environment variable.

-module(my_client_hooks).

-behaviour(shackle_hooks).
-export([
    metrics/4
]).

metrics(Client, counter, Key, Value) ->
    statsderl:increment(key(Client, Key), Value, 0.005);
metrics(Client, timing, Key, Value) ->
    statsderl:timing(key(Client, Key), Value, 0.005).

key(Client, Key) ->
    [<<"shackle.">>, atom_to_binary(Client, latin1), <<".">>, Key].
{shackle, [
  {hooks, [
    {metrics {my_client_hooks, metrics}}
  ]}
]}

Tests

make dialyzer
make elvis
make eunit
make xref

Performance testing

To run performance testing targets you must first start the server:

./bin/server.sh

Then you can run the bench or profile target:

make bench
make profile

Clients

Name Description
anchor Memcached Client
buoy HTTP 1.1 Client
flare Kafka Producer
marina Cassandra CQL Client
statsderl StatsD Client

License

The MIT License (MIT)

Copyright (c) 2015-2020 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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].