Scalable C

“We use C most often to write libraries, which we then call from applications in other languages. This layer of C libraries sits between the operating system and the application.

This layer provides security, user interfaces, audio and video, maths, graphics, databases, communications, compression, and so on. I call this the “fabric layer.”

For the most part, this fabric layer sees the world as a single processor. It has no concept of concurrency. It cannot take advantage of many cores on a machine, let alone many machines in a cloud. Every library has its own style, standards, and API model. Every library has a custom build process.

A scalable technology can solve large problems as well as small ones. Our current fabric layer is not scalable. It costs too much to write and to use.

What I will explain in this book is how to build a scalable fabric layer, written in “Scalable C.”

Scalable C has specific properties:

  • It is cheap to create a Scalable C project.

  • It is cheap to use, with consistent and obvious APIs.

  • It is cheap to deploy, with powerful tools and packagers.

  • It is cheap to scale to many cores, with actor-based concurrency.

  • It is cheap to scale to many servers, with clustering across a cloud or data center.

  • It is cheap to build community, with a modern collaborative process.

Scalable C is standard portable C plus a mix of other technologies:

  • The CLASS RFC defines the Scalable C language style.

  • ZeroMQ provides message passing between threads and processes.

  • CZMQ provides a core C library for Scalable C.

  • Zyre provides local-area clustering for Scalable C projects.

  • zproject provides packaging (builds, bindings, and distributions).

  • zproto provides client-server meta-programming.

  • The C4.1 RFC defines a collaborative process for scalability.


nanomsg is a socket library that provides several common communication patterns. It aims to make the networking layer fast, scalable, and easy to use. Implemented in C, it works on a wide range of operating systems with no further dependencies.

The communication patterns, also called “scalability protocols”, are basic blocks for building distributed systems. By combining them you can create a vast array of distributed applications. The following scalability protocols are currently available:

  • PAIR – simple one-to-one communication
  • BUS – simple many-to-many communication
  • REQREP – allows to build clusters of stateless services to process user requests
  • PUBSUB – distributes messages to large sets of interested subscribers
  • PIPELINE – aggregates messages from multiple sources and load balances them among many destinations
  • SURVEY – allows to query state of multiple applications in a single go

Scalability protocols are layered on top of the transport layer in the network stack. At the moment, the nanomsg library supports the following transports mechanisms:

  • INPROC – transport within a process (between threads, modules etc.)
  • IPC – transport between processes on a single machine
  • TCP – network transport via TCP

The library exposes a BSD-socket-like C API to the applications.

It is licensed under MIT/X11 license.

“nanomsg” is a trademark of Martin Sustrik…”

Using ZeroMQ devices to support complex network topologies

“Continuing in my ZeroMQ series, today I’d like to look at ZeroMQ “devices” and how you can integrate ZeroMQ with Gevent so you can combine the easy networking topologies of ZeroMQ with the cooperative multitasking of ZeroMQ. If you’re just getting started with ZeroMQ, you might want to check out the following articles:

Distributed Systems with ZeroMQ and ZeroMQ flow control and other options

“Departing a bit from my current series on gevent and Python, today I want to take a look at a different networking technology that’s been gaining traction: ZeroMQ. So without further ado, let’s jump right in…”

“One of the awesome things you may have noticed about ZeroMQ is that you can send a message without waiting for it to be received. In fact, the endpoint that’s going to receive the message doesn’t even need to be connected, and your application will happily act as if the message is winging its way along. While this is great for easily getting up to speed with ZeroMQ, there are some things you need to be aware of…”

Distributed Systems with ZeroMQ

“One of the first things to understand about ZeroMQ is that it’s not a message broker like you might assume from its name. ZeroMQ is a library that supports certain network communication patterns using sockets. The “MQ” part comes in because ZeroMQ uses queues internally to buffer messages so that you don’t block your application when sending data. When you say socket.send(...), ZeroMQ actually enqueues a message to be sent later by a dedicated communication thread. (This communication thread and its state are encapsulated in the ZeroMQ Context object used below; most programs will have a single Context.)…”