Nchan is the result of a complete refactoring of the Nginx HTTP Push Module codebase. Many features have been added, but a select few have also been removed:
Push Module | Nchan | |
---|---|---|
Storage Engine | Shared Memory | Shared Memory, Redis (with local shared-memory cache) |
Internal Concurrency Model | One shared-access mutex. Workers cannot access shared memory while another is holding the mutex lock, and the event loop is blocked while waiting for the mutex. | No mutexes or blocking locks used. Each nginx worker is responsible for a shard of the channel id space. Workers communicate with each other via unix pipes (sockets) sending roughly 60-byte messages containing pointers to shared memory and metadata. The event loop is never blocked, and workers are always available to handle connections. |
Horizontal Scaling | No built-in features to scale across multiple Nginx instances. |
Can be quickly scaled up horizontally across Nginx instances using Redis. |
Subscribers | Long-Poll, Interval-Poll | Websocket, EventSource, Long-Poll, Interval-Poll, HTTP Chunked Transfer, HTTP Multipart/Mixed |
Publishers | HTTP | HTTP, Websocket |
Channel Multiplexing | none | Up to 255 channels per location |
Data Persistence | Persistent across nginx reloads (via SIGHUP). No persistence after nginx shutdown |
No persistence without Redis.
*
With Redis, data persists across reloads and after shutdown.
* - In-memory persistence across reloads without redis may be implemented in the future. If you want this feature, let me know. |
Metadata and Debugging Support |
|
|
Channel Security |
|
|
Subscriber Concurrency |
Broadcast, First-In, Last-In. The latter two only allow one subscriber per channel, kicking out either the newest or oldest subscribers. |
Broadcast concurrency only. First-In can be replicated with
|
The main change is that all configuration directives have been renamed from push_*
to nchan_*
. However,
all Push Module configuration directives) are still recognized,
although a few of the very rarely used ones are now ignored. You can run Nchan with your old Push Module configuration unchanged, but it's recommended that you update it.
The Channel ID can now be set with a config directive, nchan_channel_id
(or nchan_publisher_channel_id
and nchan_subscriber_channel_id
). The old method of setting the channel id variable $push_channel_id
is still supported:
Push Module | Nchan |
---|---|
#the old, lame, Push Module way
location ... {
set $push_channel_id $foobar;
#...
}
|
#the new, super-cool, Nchan way
location ... {
nchan_channel_id $foobar;
}
|
push_min_message_buffer_length
has been removed. The presence of this setting is tolerated but will be ignored.
This setting preserved a given number of messages per channel regardless of message expiration configuration. I removed this because it complicated the message buffer configuration, and I have not seen any use of this option in the wild. If you really want this option back, let me know.
push_subscriber_concurrency
has been removed, and always assumed to be "broadcast". The presence of this setting is tolerated but will be ignored.
Concurrency | Push Module | Nchan |
---|---|---|
broadcast |
location ... {
push_subscriber_concurrency broadcast;
#...
}
|
location ... {
#broadcast by default
#...
}
|
first-in |
location ... {
push_subscriber_concurrency first-in;
#...
}
|
location ... {
nchan_max_channel_subscribers 1;
#...
}
|
last-in |
location ... {
push_subscriber_concurrency last-in;
#...
}
|
Not supported |
push_authorized_channels_only
is now nchan_subscribe_existing_channels_only