Code Monkey home page Code Monkey logo

racket-zmq-examples's Introduction

racket-zmq-examples

This repository contains examples of using Jay McCarthy's zeromq Racket FFI bindings. They replicate Clojure examples from this blog post.

Requirements

The native zeromq library must be installed for the examples to work. They use the Racket binding to zeromq's zmq_proxy call. As such, zeromq version 3.2.x must be installed.

Examples Descriptions

  1. request-router.rkt and response-router.rkt. These two scripts operate in tandem. The first script sends 100000 requests to the a set of responders which reply to the original requests

Running the examples

Implementation Details

All examples use Racket's places API. The Racket VM runs on a single native thread. Racket's thread API implements a thread as green threads (implemented most likely as Scheme co-routines).

This causes problems, though, when attempting to use zeromq's reply and request sockets in the same process; these sockets block the currently running thread until the reply and request messages are received on either socket. Using these sockets with Racket's green thread simply blocks the whole Racket process.

As a workaround, the examples use Racket 'places' API. Each place actually runs on a native thread, so spawning off the sockets in a Racket place means that Racket VM that spawns them is not blocked.

Using Racket 'places' also provides an additional bonus. The places are distributed across multiple CPUs.

The disadvantage of a Racket place is that each place is actually a separate Racket environment managed by the Racket environment that spawned the place. Each place therefore consumes as much memory as the process that spawns them. For example, on my machine, a single Racket VM costs around 100MB of memory. But while the request-router.rkt runs, the Racket process balloons to 700MB's of memory. It shrinks back down after the number of requests take place.

Zeromq Examples vs Racket's Distributed Places

The code in request-router.rkt and response-router.rkt operate in a way which is very similar to Racket's distributed-places. Distributes-place are places that can operate on remote endpoints across a network. The zeromq examples, with a few tweaks, could operate similarly, since the sockets operate across an tcp channel.

There is, though, an important different. The messages between zeromq sockets are composed of bytes (Racket byte-strings). In contrast, the data between Racket's distributed places are high-level abstractions such as vectors.

License

All examples are MIT licensed

racket-zmq-examples's People

Contributors

neomantic avatar

Stargazers

Sahin Habesoglu avatar Sungjin Chun avatar Jay McCarthy avatar

Watchers

James Cloos avatar

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.