Commit ac88e18b authored by Wandenberg Peixoto's avatar Wandenberg Peixoto

improving documentation

parent 561f16aa
h2. Version 0.2.0
* Fixing bugs on release shared memory
* Fixing bug on receive POST with empty message
* Adding a different location to get channels statistics *push_stream_channels_statistics*
* Adding new directives "push_stream_max_number_of_channels":#push_stream_max_number_of_channels, "push_stream_max_number_of_broadcast_channels":#push_stream_max_number_of_broadcast_channels and "push_stream_memory_cleanup_timeout":#push_stream_memory_cleanup_timeout
* Removed support to PUT and DELETE http methods on publisher location
* Removed different types of return on publishing messages in case that was published on a empty channel or on one which has subscribers
* Removed directive push_stream_subscriber_disconnect_interval, this interval is calculate based on push_stream_subscriber_connection_timeout
* Change default values of some directives
(head). | directive | old value | new value |
|"push_stream_min_message_buffer_timeout":#push_stream_min_message_buffer_timeout|7200 seconds|_unset_|
|"push_stream_max_message_buffer_length":#push_stream_max_message_buffer_length|10|_unset_|
|"push_stream_authorized_channels_only":#push_stream_authorized_channels_only|on|off|
|"push_stream_store_messages":#push_stream_store_messages|on|off|
|"push_stream_max_channel_id_length":#push_stream_max_channel_id_length|1024 bytes|_unset_|
|"push_stream_broadcast_channel_max_qtd":#push_stream_broadcast_channel_max_qtd|1|_unset_|
h2. Version 0.1.0
Initial version of this module was based on "pushmodule":http://pushmodule.slact.net
...@@ -4,8 +4,14 @@ A pure stream http push technology for your Nginx setup. ...@@ -4,8 +4,14 @@ A pure stream http push technology for your Nginx setup.
Comet made easy and *really scalable*. Comet made easy and *really scalable*.
* "Installing":#installing
* "Basic Configuration":#basic-configuration
* "Basic Usage":#basic-usage
* "Configuration":#configuration
* "Attention":#attention
h2. Installing
h2(#installing). Installing
<pre> <pre>
<code> <code>
...@@ -20,20 +26,20 @@ h2. Installing ...@@ -20,20 +26,20 @@ h2. Installing
# finish # finish
sudo make install sudo make install
# checking # check
sudo /usr/local/nginx/sbin/nginx -v sudo /usr/local/nginx/sbin/nginx -v
nginx version: nginx/0.8.54 nginx version: nginx/0.8.54
sudo /usr/local/nginx/sbin/nginx -c nginx-push-stream-module/misc/nginx.conf -t sudo /usr/local/nginx/sbin/nginx -c nginx-push-stream-module/misc/nginx.conf -t
the configuration file nginx-push-stream-module/misc/nginx.conf syntax is ok the configuration file nginx-push-stream-module/misc/nginx.conf syntax is ok
configuration file nginx-push-stream-module/misc/nginx.conf test is successful configuration file nginx-push-stream-module/misc/nginx.conf test is successful
# running # run
sudo /usr/local/nginx/sbin/nginx -c nginx-push-stream-module/misc/nginx.conf sudo /usr/local/nginx/sbin/nginx -c nginx-push-stream-module/misc/nginx.conf
</code> </code>
</pre> </pre>
h2. Basic Configuration h2(#basic-configuration). Basic Configuration
<pre> <pre>
<code> <code>
...@@ -53,6 +59,8 @@ h2. Basic Configuration ...@@ -53,6 +59,8 @@ h2. Basic Configuration
set $push_stream_channel_id $arg_id; set $push_stream_channel_id $arg_id;
# message template # message template
push_stream_message_template "<script>p(~id~,'~channel~','~text~');</script>"; push_stream_message_template "<script>p(~id~,'~channel~','~text~');</script>";
# store messages in memory
push_stream_store_messages on;
# max messages to store in memory # max messages to store in memory
push_stream_max_message_buffer_length 20; push_stream_max_message_buffer_length 20;
# message ttl # message ttl
...@@ -81,10 +89,9 @@ h2. Basic Configuration ...@@ -81,10 +89,9 @@ h2. Basic Configuration
push_stream_authorized_channels_only off; push_stream_authorized_channels_only off;
# ping frequency # ping frequency
push_stream_ping_message_interval 10s; push_stream_ping_message_interval 10s;
# disconnection candidates test frequency
push_stream_subscriber_disconnect_interval 30s;
# connection ttl to enable recycle # connection ttl to enable recycle
push_stream_subscriber_connection_timeout 15m; push_stream_subscriber_connection_timeout 15m;
# solving some leakage problem with persistent connections in # solving some leakage problem with persistent connections in
# Nginx's chunked filter (ngx_http_chunked_filter_module.c) # Nginx's chunked filter (ngx_http_chunked_filter_module.c)
chunked_transfer_encoding off; chunked_transfer_encoding off;
...@@ -93,7 +100,7 @@ h2. Basic Configuration ...@@ -93,7 +100,7 @@ h2. Basic Configuration
</pre> </pre>
h2. Basic Usage h2(#basic-usage). Basic Usage
You can feel the flavor right now at the command line. Try using more than You can feel the flavor right now at the command line. Try using more than
one terminal and start playing http pubsub: one terminal and start playing http pubsub:
...@@ -119,3 +126,290 @@ one terminal and start playing http pubsub: ...@@ -119,3 +126,290 @@ one terminal and start playing http pubsub:
curl -s -v "http://localhost/channels_stats?id=my_channel_1" curl -s -v "http://localhost/channels_stats?id=my_channel_1"
</code> </code>
</pre> </pre>
h2(#configuration). Configuration
h3. Variables
(head). | variable | values | location |
|"push_stream_channel_id":#push_stream_channel_id |channel id|push_stream_publisher, push_stream_channels_statistics|
|"push_stream_channels_path":#push_stream_channels_path |set of channels id and backtrack desired messages|push_stream_subscriber|
h4(#push_stream_channel_id). push_stream_channel_id
A string to uniquely identify a communication channel. Must be present on location of the push_stream_publisher and push_stream_channels_statistics.
<pre>
<code>
set $push_channel_id $arg_id;
#channel id is now the url query string parameter "id"
#(/pub?id=channel_id_string or /channels_stats?id=channel_id_string)
</code>
</pre>
h4(#push_stream_channels_path). push_stream_channels_path
A string representing a set of channels id and backtrack desired messages separated by slash, example _/channel1.b3/channel2.b5/channel3.b2_.
The backtrack means the amount of old messages from each of the channels that will be delivered to the subscriber. On the example will be 3 messages from channel1, 5 from channel2 and 2 from channel3.
Backtrack isn't needed, you can only sign channels without get old messages, or you can mix things.
More accepted examples: _/channel1_, _/channel1/channel2_, _/channel1.b5/channel2_, _/channel1/channel2.b6_, ...
Must be present on location of the push_stream_subscriber.
<pre>
<code>
location /sub/(.*) {
set $push_stream_channels_path $1;
}
#channels path is now part of url
#(/sub/channel_id_string or /sub/channel_id_string.b2/other_channel)
</code>
</pre>
h3. Directives
(head). | directive | default value | values | context | location |
|"push_stream_channels_statistics":#push_stream_channels_statistics |-|-|location|-|
|"push_stream_publisher":#push_stream_publisher |-|-|location|-|
|"push_stream_subscriber":#push_stream_subscriber |-|-|location|-|
|"push_stream_max_reserved_memory":#push_stream_max_reserved_memory |32M|size greater than 8 * ngx_pagesize|http|main nginx configuration|
|"push_stream_store_messages":#push_stream_store_messages |off|on, off|location|push_stream_publisher|
|"push_stream_min_message_buffer_timeout":#push_stream_min_message_buffer_timeout |unset|time constant|location|push_stream_publisher|
|"push_stream_max_message_buffer_length":#push_stream_max_message_buffer_length |unset|number|location|push_stream_publisher|
|"push_stream_authorized_channels_only":#push_stream_authorized_channels_only |off|on, off|location|push_stream_subscriber|
|"push_stream_header_template":#push_stream_header_template |unset|any string|location|push_stream_subscriber|
|"push_stream_content_type":#push_stream_content_type |text/plain|any valid content type|location|push_stream_subscriber|
|"push_stream_ping_message_interval":#push_stream_ping_message_interval |unset|time constant|location|push_stream_subscriber|
|"push_stream_subscriber_connection_timeout":#push_stream_subscriber_connection_timeout |unset|time constant|location|push_stream_subscriber|
|"push_stream_broadcast_channel_max_qtd":#push_stream_broadcast_channel_max_qtd |unset|number|location|push_stream_subscriber|
|"push_stream_max_channel_id_length":#push_stream_max_channel_id_length |unset|number|http, location|(push_stream_subscriber and push_stream_publisher) or main nginx configuration|
|"push_stream_broadcast_channel_prefix":#push_stream_broadcast_channel_prefix |unset|any string|http, location|(push_stream_subscriber and push_stream_publisher) or main nginx configuration|
|"push_stream_message_template":#push_stream_message_template |unset|any string|http, location|(push_stream_subscriber and push_stream_publisher) or main nginx configuration|
|"push_stream_max_number_of_channels":#push_stream_max_number_of_channels |unset|number|http, location|(push_stream_subscriber and push_stream_publisher) or main nginx configuration|
|"push_stream_max_number_of_broadcast_channels":#push_stream_max_number_of_broadcast_channels |unset|number|http, location|(push_stream_subscriber and push_stream_publisher) or main nginx configuration|
|"push_stream_memory_cleanup_timeout":#push_stream_memory_cleanup_timeout |30 seconds|time constant|http, location|(push_stream_subscriber and push_stream_publisher) or main nginx configuration|
h4(#push_stream_channels_statistics). push_stream_channels_statistics
New in version 0.2.0
context: location
Defines a location as a source of statistics. You can use this location to get statistics about a specific channel, or about all channels, in a resumed ou summarized way.
To get statistics about all channels in a summarized way you have to make a GET in this location without specify a name in the "push_stream_channel_id":#push_stream_channel_id variable .
To get statistics about all channels in a detailed way you have to specify "ALL" in the "push_stream_channel_id":#push_stream_channel_id variable .
To get statistics about a channel you have to specify the name in the "push_stream_channel_id":#push_stream_channel_id variable .
You can get statistics in the formats plain, xml, yaml and json. The default is json, to change this behavior you can use *Accept* header parameter passing values like "text/plain", "application/xml", "application/yaml" and "application/json" respectivelly.
<pre>
<code>
location /channels_stats {
push_stream_channels_statistics;
set $push_stream_channel_id $arg_id;
}
# /channels_stats -> get statistics about all channels in a summarized way
# /channels_stats?id=ALL -> get statistics about all channels in a detailed way
# /channels_stats?id=channel_id -> get statistics about a channel
</code>
</pre>
h4(#push_stream_publisher). push_stream_publisher
context: location
Defines a location as a message publisher. Requests to a publisher location are treated as messages to be sent to subscribers.
This location supports two http methods:
GET, make possible to get statistics about the channel
POST, publish a message to the channel
<pre>
<code>
location /pub {
push_stream_publisher;
set $push_stream_channel_id $arg_id;
}
# GET /pub?id=channel_id -> get statistics about a channel
# POST /pub?id=channel_id -> publish a message to the channel
</code>
</pre>
h4(#push_stream_subscriber). push_stream_subscriber
context: location
Defines a location as a subscriber. This location represents a subscriber's interface to a channel's message queue.
This location only supports GET http method to receive published messages in a stream.
h3. Functionality
h4(#push_stream_header_template). push_stream_header_template [ string ]
default: -
context: location
location: push_stream_subscriber
The text that will be sended to subscribers when they arrive.
h4(#push_stream_message_template). push_stream_message_template [ string ]
default: -
context: location
location: (push_stream_subscriber and push_stream_publisher) or main nginx configuration
The text template that will be used to format the message before be sended to subscribers. The template can contain any number of the reserved words: ==~id~, ~text~ and ~channel~, example: "<script>p(~id~,'~channel~','~text~');</script>"==
h4(#push_stream_content_type). push_stream_content_type [ string ]
default: text/plain
context: location
location: push_stream_subscriber
The content type used on responses to subscribers. Must be complient with "push_stream_header_template":#push_stream_header_template and "push_stream_message_template":#push_stream_message_template.
h4(#push_stream_ping_message_interval). push_stream_ping_message_interval [ time ]
default: -
context: location
location: push_stream_subscriber
The time interval in which a keepalive message is sent to subscribers.
h3. Message/Channel Storage
h4(#push_stream_max_reserved_memory). push_stream_max_reserved_memory [ size ]
default: 32M
context: http
The size of the memory chunk this module will use to store published messages, channels and other shared structures.
When this memory is full any new request for publish a message or subscribe a channel will receive an 500 Internal Server Error response.
h4(#push_stream_store_messages). push_stream_store_messages [ on | off ]
default: off
context: location
location: push_stream_publisher
Whether or not message queuing is enabled.
If store messages is "On" is needed to set at least one of these two directives "push_stream_min_message_buffer_timeout":#push_stream_min_message_buffer_timeout or "push_stream_max_message_buffer_length":#push_stream_max_message_buffer_length.
h4(#push_stream_min_message_buffer_timeout). push_stream_min_message_buffer_timeout [ time ]
default: -
context: location
location: push_stream_publisher
The length of time a message may be queued before it is considered expired. If you do not want messages to expire, just not set this directive.
h4(#push_stream_max_message_buffer_length). push_stream_max_message_buffer_length [ number ]
default: -
context: location
location: push_stream_publisher
The maximum number of messages to store per channel. A channel's message buffer will retain at most this many most recent messages. If you do not want messages to be discarded by length, just not set this directive.
h3. Security
h4(#push_stream_authorized_channels_only). push_stream_authorized_channels_only [ on | off ]
default: off
context: location
location: push_stream_subscriber
Whether or not a subscriber may create a channel by making a request to a push_stream_subscriber location. If set to on, a publisher must send a POST request before a subscriber can request messages on the channel. Otherwise, all subscriber requests to nonexistent channels will get a 403 Forbidden response.
This restriction is not applied to broadcast channels, but to subscribe to a broadcast channel is necessary to subscribe at least to one normal channel, and if this directive is set to on this channel has to be created before.
h4(#push_stream_subscriber_connection_timeout). push_stream_subscriber_connection_timeout [ time ]
default: -
context: location
location: push_stream_subscriber
The length of time a subscriber will stay connected before it is considered expired and disconnected. If you do not want subscribers to be automatically disconnected, just not set this directive.
But, this operation is very important to help Nginx recycle memory consumed to send messages to susbscriber, allocated at pool request.
h4(#push_stream_max_channel_id_length). push_stream_max_channel_id_length [ number ]
default: -
context: location
location: (push_stream_subscriber and push_stream_publisher) or main nginx configuration
Maximum permissible channel id length (number of characters). Longer ids will receive an 400 Bad Request response.
h4(#push_stream_broadcast_channel_prefix). push_stream_broadcast_channel_prefix [ string ]
default: -
context: location
location: (push_stream_subscriber and push_stream_publisher) or main nginx configuration
The string prefix used to identify when a channel is as normal or broadcast channel, example: when you set this directive as "bd_", "bd_ch1" will be a broadcast channel
h4(#push_stream_broadcast_channel_max_qtd). push_stream_broadcast_channel_max_qtd [ number ]
default: -
context: location
location: (push_stream_subscriber and push_stream_publisher) or main nginx configuration
The maximum number of broadcast channels that a subscriber may sign on the request.
This directive works in conjunction with "push_stream_authorized_channels_only":#push_stream_authorized_channels_only to preserve the server from a kind of attack where a subscriber sign one normal channel and many nonexistent broadcast channels.
h4(#push_stream_max_number_of_channels). push_stream_max_number_of_channels [ number ]
default: -
context: location
location: (push_stream_subscriber and push_stream_publisher) or main nginx configuration
The maximum number of concurrent channels on the server. If you do not want to limit the number of channels, just not set this directive.
h4(#push_stream_max_number_of_broadcast_channels). push_stream_max_number_of_broadcast_channels [ number ]
default: -
context: location
location: (push_stream_subscriber and push_stream_publisher) or main nginx configuration
The maximum number of concurrent broadcats channels on the server. If you do not want to limit the number of broadcast channels, just not set this directive.
h4(#push_stream_memory_cleanup_timeout). push_stream_memory_cleanup_timeout [ time ]
default: 30 seconds
context: location
location: (push_stream_subscriber and push_stream_publisher) or main nginx configuration
The length of time a message or a channel will stay on garbage collection area before it is completly discarded, freeing the shared memory. The minimum length is 30 seconds to ensure that no one is using these elements.
This operation is very important to help Nginx recycle memory consumed to create messages and channels, so do not use a large time.
h2(#attention). Attention
This module controls everything needed to send the messages to subscribers.
So is strongly recommended to you disable Nginx's chuncked filter to reduce memory consumption.
You can do this using the _chunked_transfer_encoding_ directive on subscriber location
<pre>
<code>
# solving some leakage problem with persistent connections in
# Nginx's chunked filter (ngx_http_chunked_filter_module.c)
chunked_transfer_encoding off;
</code>
</pre>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment