flare icon indicating copy to clipboard operation
flare copied to clipboard

High Performance Erlang Kafka Producer

flare

High Performance Erlang Kafka Producer

Build Status Coverage Status

Features

  • Backpressure via backlog (OOM protection)
  • Compression support (snappy)
  • Performance optimized
  • Topic buffering (delay, size)

API

Function Index

Environment variables

Name Type Default Description
broker_bootstrap_servers [{inet:ip_address() | inet:hostname(), inet:port_number()}] [{"127.0.0.1", 9092}] Bootstrap servers used to query topic metadata
broker_pool_size pos_integer() 4 Number of connections per broker
broker_pool_strategy random | round_robin random Broker connection selection strategy
broker_reconnect boolean() true Reconnect closed broker connections
broker_reconnect_time_max pos_integer() | infinity 120000 (120s) Maximum reconnect time (milliseconds)
broker_reconnect_time_min non_neg_integer() 2000 (2s) Minimum reconnect time (milliseconds)
query_api_versions boolean() true Set to false when using Kafka version 0.9 or less

Topic options

Name Type Default Description
acks -1..1 | all_isr | none | leader_only 1 Number of acknowledgements required for a succeful produce
buffer_delay pos_integer() 1000 (1s) Maximun delay (milliseconds) before flushing the buffer
buffer_size pos_integer() 100000 Maximun buffer size before flushing
compression no_compression | gzip | snappy gzip Compression configuration
metadata_delay pos_integer() 300000 (300 s) Maximun delay (milliseconds) before reloading metadata
pool_size pos_integer() 2 Number of topic buffer proccesses

Examples

1> flare_app:start().
{ok, [metal, compiler, syntax_tools, foil, granderl, shackle, flare]}
2> flare_topic:start(<<"my_topic">>, [{compression, snappy}]).
ok
3> Timestamp = flare_utils:timestamp().
1548011068201
4> flare:produce(<<"my_topic">>, Timestamp, <<"key">>, <<"value">>, [], 500).
ok
5> {ok, ReqId} = flare:async_produce(<<"my_topic">>, Timestamp, <<"key">>, <<"value">>, [], self()).
{ok, {{1548, 11081, 884262}, <0.349.0>}}
6> flare:receive_response(ReqId, 500).
ok
7> flare:receive_response(ReqId, 500).
ok
8> flare_topic:stop(<<"my_topic">>).
ok

Tests

make dialyzer
make elvis
make eunit
make xref

Performance testing

To run the profile target you must first start kafka:

./bin/zookeeper-server-start.sh config/zookeeper.properties &
./bin/kafka-server-start.sh config/server.properties &

Then you can run the profile target:

make profile

License

The MIT License (MIT)

Copyright (c) 2016-2019 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.