Skip to content

edurange/demo-namedpipe-log-writer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

demo-namedpipe-log-writer

Demonstrates reading/writing (for something like a log) using a named pipe for concurrency without polling.

This is a demo of using a fifo via the fifo utility for concurrent IO between two processes, such as a log producer and log consumer.

Instructions

To run it one can use ./toy_start_log.sh - which is a very reductive mock of start_ttylog.sh. The commands from toy_start_log.sh are easy to run manually, as well.

Explanation

Previous versions rely heavily on polling and other busy waiting when coordinating between processes. Code that uses appropriate synchronization mechanisms is more performant, and easier to read and maintain.

"fifos", also known as "named pipes", are one of the core building blocks of inter-process communication on POSIX/UNIX platforms. In line with UNIX "everything is a file" design thinking, they look just like a file. But they have no persistent storage. They are a temporary first-in first-out queue.

Fifos behave differently from files in one other key way. When a reader is reading from a normal file and reaches the end of the data, the filesystem sends an end-of-file character. When the file is a fifo, a read or seek beyond the end of the buffer simply blocks.

This is important because many core programming language libraries which implement basic IO with the operating system respond to the EOF character by closing the file and releasing the file descriptor. In a live data pipeline, we know that most of the time when we run out of data, there will be more ready for us very soon.

About

Demonstrates log reading/writing using a named pipe for concurrency without polling

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors