Skip to content

Commit

Permalink
docs: route compression
Browse files Browse the repository at this point in the history
  • Loading branch information
lonng committed Aug 8, 2017
1 parent d499a6e commit eae7154
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ go get -u github.com/gorilla/websocket
## Documents

- [How to build your first nano application](./docs/get_started.md)
- [Route compression](./docs/route_compression.md)
- [Communication protocol](./docs/communication_protocol.md)
- [Design patterns](./docs/design_patterns.md)

Expand Down
50 changes: 50 additions & 0 deletions docs/route_compression.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Route compression

***STATUS: DRAFT***

## Why need route compression

In practice, network bandwidth is a worthwhile consideration. Especially for mobile clients,
the network resource is often not very rich, in order to save network resources, it is often
needed to increase the effective payload ratio.

Using the chat application as an example, when a user send a chat message, the route information
is required, as shown below:

```javascript

pomelo.request('Room.Join',
//...
);

```
The routing information indicates that the request should be handled by send method of Join on
Room component. When server pushing messages to the client, route also should be specified to
indicate a handler. In the chat example, there are onAdd, onLeave and other routes. Considering
if a chat message is very short such as just a letter, but when being sent, it should be added
a complete routing information, this would result in a very low effective payload ratio and wasting
network resource. The direct idea to solve this problem is to shorten the routing information.
On the server side, routing information is fixed while the server is determined. On the client
side, although you can use a very short name for route, but it may be unreadable.

## How to implement

To address this situation, nano provides the dictionary-based route compression.

* For the server side, nano scans all route information;
* For the client side, the developer needs routes map.

Then, nano would get all the routes of client side and server side and then maps each route to
a small integer. Currently nano route compression supports limit. The implementation of current
stage is that fetching routes when handshake phase, if you enable route compression, then the
client and server will synchronize the dictionary in handshake phase while establishing a
connection, so that the small integer can be used to replace the route later, and it can reduce
the transmission cost.

## Summary

So far, The format of transmission message between client and server is json. Indeed, while json
is very convenient, but it also brought some redundant information, which can be ommited to reduce
transmission cost.

***Copyright***:Parts of above content and figures come from [Pomelo Route compression](https://github.com/NetEase/pomelo/wiki/Route-compression)

0 comments on commit eae7154

Please sign in to comment.