Skip to content

Commit

Permalink
explain cost of WebSocket compression and how to disable it
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed May 14, 2014
1 parent 66c4a93 commit f917592
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/Mojo/UserAgent.pm
Expand Up @@ -877,7 +877,8 @@ L<Mojo::Transaction::HTTP> object.
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
You can activate C<permessage-deflate> compression by setting the
C<Sec-WebSocket-Extensions> header.
C<Sec-WebSocket-Extensions> header, this can result in much better
performance, but also increases memory usage by up to 300KB per connection.
my $headers = {'Sec-WebSocket-Extensions' => 'permessage-deflate'};
$ua->websocket('ws://example.com/foo' => $headers => sub {...});
Expand Down
9 changes: 9 additions & 0 deletions lib/Mojolicious/Guides/Cookbook.pod
Expand Up @@ -570,6 +570,15 @@ L<Mojolicious::Controller/"send">.
The event L<Mojo::Transaction::WebSocket/"finish"> will be emitted right after
the WebSocket connection has been closed.

$self->tx->compressed(0);
$self->res->headers->remove('Sec-WebSocket-Extensions');

By default C<permessage-deflate> compression will be used if the client
supports it, this can result in much better performance, but also increases
memory usage by up to 300KB per connection. It can be disabled with
L<Mojo::Transaction::WebSocket/"compressed"> and by removing the
C<Sec-WebSocket-Extensions> header from the WebSocket handshake response.

=head2 Testing WebSocket web services

While the message flow on WebSocket connections can be rather dynamic, it
Expand Down

0 comments on commit f917592

Please sign in to comment.