Why you should use ZZ instead of pipes in your next project
Your applications will require less memory and CPU time to transfer data.
Read below why this is so.
ZZ helps you split your application into small components
which can be rearranged by the user, which increases flexibility
and helps debugging.
Arbitrary data flows between applications can be defined, as opposed
to one-way pipe chains.
This is not more difficult than using the | (pipe) operator.
Applications communicating via ZZ need not be related in any way,
not even written in the same programming language.
libzz is designed to support wrappers.
A lot of the ground work is done for you.
You need only define callbacks. A powerful option parser is included.
Why you might prefer pipes
ZZ is not a drop-in replacement for pipes. Support for ZZ must be
built into the applications, through libzz.
ZZ is optimized for transfer of large memory chunks, since each
chunk requires allocation of a new shared memory segment.
This will be remedied in future versions.
ZZ is designed around a static model, where the network is defined
before execution begins. Data channels can not be created dynamically.
This will be remedied in future versions.
This is how a pipe works. Data is copied once into kernel space,
and once out of kernel space. There will be two copies of the same data.
This is how ZZ works. Data is never copied,
and there are no duplicates of a buffer.
What is the story behind ZZ?
The main author, Tom Weber, was fed up with the situation of the
Unix environment. The Unix design philosophy
(well described in Eric Raymond's book,
The Art of Unix Programming)
is brilliant and close to timeless, but the system itself is aging,
as it is built around past assumptions and conventions.
The trend has been towards object-oriented languages and complex
user-space frameworks, as the Unix API and C library itself become less
and less sufficient for modern applications.
The Unix environment needs to evolve.
ZZ is born out of passion for the Unix environment, and meant to
increase the efficiency, simplicity and modularity of Unix.
Anticipated questions
What is the risk for a memory leak, using shared memory?
The same as for heap memory. The segments used
by ZZ are automatically destroyed at the last detachment, and thus
will not persist after execution, no matter how execution ends.
What is the risk for someone manipulating shared memory?
The segments used by ZZ can only be attached by the same user
who created them. Segment IDs are normally not revealed to the user,
though (at least under Linux) they can be seen in
/proc/sysvipc/shm.
Why not build this into the Linux kernel instead?
Sure, why not? It might be even more efficient.
But it would not be portable. Anyone wanting to use a ZZ application
would have to patch their kernel.