go>> fep>> 返回
项目作者: egorovd

项目描述 :
Fast Erlang Pool
高级语言: C++
项目地址: git://github.com/egorovd/fep.git
创建时间: 2018-06-06T15:26:28Z
项目社区:https://github.com/egorovd/fep

开源协议:Apache License 2.0

下载


fep

Fast Erlang Pool on NIF lock-free Queue using C++ the library: moodycamel::concurrentqueue

moodycamel::ConcurrentQueue

An industrial-strength lock-free queue for C++.

Features:

  • Knock-your-socks-off blazing fast performance.
  • Single-header implementation. Just drop it in your project.
  • Fully thread-safe lock-free queue. Use concurrently from any number of threads.
  • C++11 implementation — elements are moved (instead of copied) where possible.
  • Templated, obviating the need to deal exclusively with pointers — memory is managed for you.
  • No artificial limitations on element types or maximum count.
  • Memory can be allocated once up-front, or dynamically as needed.
  • Fully portable (no assembly; all is done through standard C++11 primitives).
  • Supports super-fast bulk operations.
  • Includes a low-overhead blocking version (BlockingConcurrentQueue).
  • Exception safe.

How it works.

Sometimes you need a pool of workers when: one worker - one operation (for example, processing one connection to the server).

Build

  1. $ rebar3 compile

Using

  1. {ok, Ref} = fep:create_pool({fep_example, 1}), % Create a pool.
  2. {ok, Pid} = supervisor:start_child(worker_sup, [Ref]),
  3. % In worker.
  4. % fep:push(PoolRef)
  5. % They created workers, each worker put himself in the pool.
  6. Pid = fep:pop(Ref). % We take the worker from the pool.
  7. worker:run(Pid) % We call the worker.
  8. % The worker after processing the job, puts himself in the pool.
  9. % fep:push(PoolRef)
  10. % kill worker
  11. exit(Pid, normal).
  12. % We can check if the worker is alive before giving:
  13. empty = fep:pop_if_alive(Ref).
  14. % Or if pool not empty and process is dead.
  15. dead = fep:pop_if_alive(Ref).

Example

fep_example