Skip to content

Instantly share code, notes, and snippets.

View ztellman's full-sized avatar
💭
boiling the ocean

Zach Tellman ztellman

💭
boiling the ocean
View GitHub Profile
(require
'[manifold.stream :as s])
(defn cancellable-connect [a b]
(let [bridge (s/stream)]
(s/connect a bridge)
(s/connect bridge b)
#(s/close! bridge)))
(import
'[java.awt.geom
Ellipse2D$Double
Rectangle2D$Double])
(defn rectangle [x y w h]
(Rectangle2D$Double. x y w h))
(defn circle [x y r]
(Ellipse2D$Double. (- x r) (- y r) (* r 2) (* r 2)))
(defn split-spliced-stream [s]
(let [in (a/chan)
out (a/chan)]
(s/connect s in)
(s/connect out s)
[in out]))
(require '[manifold.deferred :as d])
(require '[manifold.stream :as s])
(defn tcp-handler [s conn-info]
(d/let-flow [s (wrap-stream protocol s)
msg (s/take! s)
_ (s/put! s (response msg))]
(set-up-message-handling s)))
(require '[manifold.stream :as s])
(->> (s/periodically period sample-state)
s/stream->seq
(take max-tries)
(remove unsettled?)
first)
(headers :uint16-be
(fn [len]
(if (zero? len)
nil-frame
[(string "iso-8859-1" :length len)
(string "iso-8859-1" :prefix :uint16-be)]))
(fn [tuple]
(if tuple
0
(count (first tuple)))))

Hey all,

In preparation for Clojure/West, I'm formally releasing the latest Aleph and the libraries that surround it. Aleph 0.4.0 has been running in production at Factual for half a year now, and across a variety of services is handling at peak 600k HTTP requests/sec (spread across 15-20 machines).

Since the landscape of Clojure HTTP servers is pretty crowded these days, it's worth taking some time to explain how Aleph differs. To be clear, most Clojure deployments likely use Jetty, and should continue to do so. However, Aleph has some unique properties:

  • It uses the Netty library, which is a high-performance and very battle-tested network layer for the JVM
  • It is the only HTTP server that has ubiquitous asynchronous streams wherever data can be received or sent (all other libraries can only represent streaming requests using InputStreams, or like http-kit don't support streaming HTTP requests at all)
  • It is the only server that has a WebSocket implementation with any support for per-connection
(defn possible-shrinks [s]
(let [cnt (count s)]
(concat
(->> (iterate #(* % 2) 1)
(take-while #(< % cnt))
reverse
(map #(drop % s)))
(->> (iterate #(* % 2) 1)
(take-while #(< % cnt))
(map #(take % s)))
(ns aleph.websocket-test
(:use
[clojure test])
(:require
[manifold.deferred :as d]
[manifold.stream :as s]
[aleph.netty :as netty]
[byte-streams :as bs]
[aleph.http :as http]))
(ns aleph-test.core
(:require [aleph.http :as aleph]
[manifold.stream :as stream]
[manifold.deferred :as deferred]
[compojure.core :as compojure]
[compojure.route :as compojure-route]
[ring.middleware.params :as ring-params]))
(def not-websocket