Giter VIP home page Giter VIP logo

yampl's Introduction

YAMPL

Introduction

YAMPL (Yet Another Message Passing Library) is a C++ library that provides a simple abstraction of inter-process (local or distributed) & inter-thread communication channels.

A channel allows to send and receive data over it. Each end of a channel is attached to a socket:

  • ClientSocket: a ClientSocket can be connected to at most one ServerSocket through a channel;
  • ServerSocket: a ServerSocket can be connected to zero ore more ClientSocket-s through a channel;

YAMPL allows to send and receive:

  • objects of trivially copiable types
  • arrays of trivially copiable types

A trivially copiable type

  • has no non-trivial copy constructors (no virtual functions or virtual bases)
  • has no non-trivial copy assignment constructors
  • has a trivial destructor

In other words, a trivially copyable type is any type for which the underlying bytes can be copied to an array of char or unsigned char and into a new object of the same type, and the resulting object would have the same value as the original.

Different communication strategies are offered to provide the best performances for the given problem:

  • Inter-thread: Lock Free Queues
  • Inter-process (local):
    • "small" messages: Lock Free Queues over POSIX Shared Memory, optimized for latency
    • "big" messages: UNIX Pipes (vmsplice), optimized for bandwidth
  • Inter-process (distributed): POSIX Sockets

Modular architecture

Each of the strategies listed anbove is implemented as a modular and independent plugin. The plugin subsystem (PluginArbiter) allows for an easy integration of new custom plugins. When YAMPL is executed, the PluginArbiter loads all available plugins at runtime, handles memory management and all the bookkeeping. The plugin subdirectory currently contains the code of three plugins. Each of them implements a specific backend for YAMPL:

  • yampl-shm: Shared Memory backend;
  • yampl-pipe: Linux Pipe backend;
  • yampl-zmq: ZeroMQ backend;

The users can easily develop their own plugins for YAMPL (e.g. for implementing IPC backends different from those listed above). YAMPL uses a strict API defining how both plugin and application must behave in order to guarantee a correct operation. This is a repository containing documentation and a minimal example of how to implement a plugin for YAMPL.

Build, Test & Install

git clone https://github.com/vitillo/yampl
cd yampl
# (Optional) Pull additional plugins. See the documentation at https://github.com/ntauth/yampl-example
# ...
# Configure project
mkdir /path/to/build/directory
cd /path/to/build/directory
cmake /path/to/repo/root -DCMAKE_INSTALL_PREFIX=/path/to/install/dir
# Build and install
make
make install
# Run tests
make test
# Run benchmarks
make example

A number of flags can be passed to CMake to customize the build:

  • WITH_EXAMPLES: Include examples in the build. Default: ON
  • WITH_TESTS: Include tests in the build. Default: ON
  • WITH_PLUGIN_[PluginId]: Include plugin yampl-[PluginId] in the build. Default: ON for SHM, PIPE and ZMQ
  • WITH_PYBIND: Include Python bindings in the build. Default: ON
  • PYBIND_ONLY: Build Python bindings only. Default: OFF
  • PYTHON_EXECUTABLE:FILEPATH: Path to the Python binary. Default: Automatically Detected
  • PYTHON_INCLUDE_DIR:PATH: Path to the Python include directory. Default: Automatically Detected
  • PYTHON_LIBRARY:FILEPATH: Path to the Python library. Default: Automatically Detected

Note that if WITH_PYBIND is enabled, a working version of Python >= 2.7 with the setuptools library installed is required. If you don't have setuptools, you can install it using pip install setuptools. If you have multiple versions of Python installed in the system, you can use the PYTHON_* flags listed above to point to a specific version of Python.

To compile and link against the YAMPL library, assuming ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig/ is in PKG_CONFIG_PATH:

g++ `pkg-config yampl --libs --cflags` foo.cpp

YAMPL is by default installed in $HOME/yampl unless you provide a CMAKE_INSTALL_PREFIX when configuring the project with CMake. Another file, .yamplrc is installed in $HOME and is used by the plugin manager to locate the plugins installed in the system.

NOTE: Depending on your system, using pipes as the communication strategy may require elevated privileges. This depends on the maximum pipe buffer size reported in /proc/sys/fs/pipe-max-size: YAMPL sets the buffer size to 1048576 bytes to maximize performance but, if this exceeds pipe-max-size, the consumer process will need to be run with elevated privileges or with CAP_SYS_RESOURCE on. If your work environment doesn't allow this, performance will be limited, so another communication strategy would be the better fit.

Python bindings

YAMPL is automatically built with -DWITH_PYBIND=ON, which seamlessly generates Python bindings. The bindings are installed in ${CMAKE_INSTALL_PREFIX}/python. In order to import the bindings, the PYTHONPATH environment variable pointing to ${CMAKE_INSTALL_PREFIX}/python has to be exported. After that the bindings can be used within Python as follows:

import yampl

socket = ClientSocket('<server_name>', '<socket_type>')
socket.send({ 'hello world!' })

For complete implementation of a Hello World example for python Yampl see:

  • tests/server_test.py
  • tests/client_test.py

yampl's People

Contributors

ntauth avatar tsulaiav avatar vitillo avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

yampl's Issues

Problems when compiling on Ubuntu

Hi,

I'm trying to compile yampl on Ubuntu 18.04 with gcc 6.2.0 as part of Ath(Simulation)Externals.

  1. I get the following errors when compiling:
[ 44%] Building CXX object CMakeFiles/CLHEPS.dir/Random/src/RandEngine.cc.o
size.cpp: In function 'int main(int, char**)':
size.cpp:66:5: error: 'wait' was not declared in this scope
     wait();
     ^~~~
size.cpp:66:5: note: suggested alternative: 'main'
     wait();
     ^~~~
     main
Makefile:10: recipe for target 'size' failed
make[4]: *** [size] Error 1
[ 44%] Building CXX object CMakeFiles/CLHEP.dir/Random/src/MixMaxRng.cc.o
calls.cpp: In function 'int main()':
calls.cpp:58:5: error: 'wait' was not declared in this scope
     wait();
     ^~~~
calls.cpp:58:5: note: suggested alternative: 'main'
     wait();
     ^~~~
     main
Makefile:10: recipe for target 'calls' failed
make[4]: *** [calls] Error 1
[ 68%] Building CXX object CMakeFiles/GeoModelKernel.dir/src/GeoPhysVol.cxx.o
dest.cpp: In function 'int main(int, char**)':
dest.cpp:58:5: error: 'wait' was not declared in this scope
     wait();
     ^~~~
dest.cpp:58:5: note: suggested alternative: 'main'
     wait();
     ^~~~
     main
Makefile:10: recipe for target 'dest' failed
make[4]: *** [dest] Error 1
make[4]: Target 'all' not remade because of errors.
Makefile:42: recipe for target 'tests' failed
make[3]: *** [tests] Error 2
make[3]: Target 'all' not remade because of errors.

I haven't been able to locate where wait() is from, so I just dropped it from the tests source files for now.

cp: failed to access '/home/ubuntu/build/build/AthSimulationExternals/External/yampl/CMakeFiles/yamplBuild/lib/pkgconfig/': Not a directory
Makefile:45: recipe for target 'install' failed
make[3]: *** [install] Error 1
External/yampl/CMakeFiles/yampl.dir/build.make:73: recipe for target 'src/yampl-stamp/yampl-install' failed
make[2]: *** [src/yampl-stamp/yampl-install] Error 2
make[2]: Target 'External/yampl/CMakeFiles/yampl.dir/build' not remade because of errors.
CMakeFiles/Makefile2:2575: recipe for target 'External/yampl/CMakeFiles/yampl.dir/all' failed

.../lib/pkgconfig/ does not exist. However, if I look in ../yamplBuild, I see:

ubuntu@atlas-ubuntu:~$ ll /home/ubuntu/build/build/AthSimulationExternals/External/yampl/CMakeFiles/yamplBuild/
total 5748
drwxrwxr-x 3 ubuntu ubuntu    4096 Dec 19 08:32 ./
drwxrwxr-x 6 ubuntu ubuntu    4096 Dec 19 08:46 ../
-rwxrwxr-x 1 ubuntu ubuntu 5871280 Dec 19 08:46 lib*
drwxrwxr-x 3 ubuntu ubuntu    4096 Dec 19 08:32 {lib/
ubuntu@atlas-ubuntu:~$ ll /home/ubuntu/build/build/AthSimulationExternals/External/yampl/CMakeFiles/yamplBuild/{lib
total 12
drwxrwxr-x 3 ubuntu ubuntu 4096 Dec 19 08:32 ./
drwxrwxr-x 3 ubuntu ubuntu 4096 Dec 19 08:32 ../
drwxrwxr-x 2 ubuntu ubuntu 4096 Dec 19 08:32 pkgconfig,include}/

Did some string manipulation go wrong?!

Thanks,
Justin

request for suggestions about stuck data-receiving

Hi,
I'm using yampl for a multi-threaded client-server communication.
the server socket is set as:

char buff[1000];
snprintf(buff,1000,"%s_%u",m_channelName.c_str(),userUID);
yampl::Channel channelS(buff,yampl::LOCAL_SHM);
yampl::SocketFactory factory;
factory.createServerSocket(channelS);
m_socket->tryRecv(buff,100l,source);

the client socket is set as:
yampl::ISocket m_mySocket;
char buff[1000];
snprintf(buff,1000,"%s
%u",m_connName.c_str(),userUID);
yampl::Channel apeChannel(buff,yampl::LOCAL_SHM);
yampl::SocketFactory sf;
m_mySocket=sf.createClientSocket(apeChannel);
std::unique_ptr &buff
m_mySocket->send(myClass::getRawBuffer(_buff),transferSize);

when data (~12 MB) are sent from client to server process gets stuck
and no exceptions or timeout are thrown: are there any rules of thumb or troubleshooting
tips I have to check for in order to figure out what's going on?

thanks
Salvatore

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.