Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compression websocket messages #2482

Open
repbl444 opened this issue Oct 19, 2022 · 8 comments
Open

Compression websocket messages #2482

repbl444 opened this issue Oct 19, 2022 · 8 comments
Assignees

Comments

@repbl444
Copy link

repbl444 commented Oct 19, 2022

Hello guys, I am trying to find a solution for compression websocket messages, if you can help, it will be very nice

  • atmosphere version 2.7.6
  • atmosphere.js 3.1.3

I want to find a way to compress messages I have in Json formats, cause they are huge,
For investigating I used meteor-chat sample and spring-boot-chat-atmosphere-sample
I found an issue about this with a link https://github.com/Atmosphere/atmosphere/issues/2039/ and did all thing to implement the compression, but as I understand it didn't work. For example, I tried to add some JSR356 support to web.xml in meteor-chat sample or init parameters to the ServletRegistrationBean in spring-boot-sample, changed configuration in domain.xml for payara5(glassfish5) and server.xml in tomcat9 to change settings of the ServletContainer. Tried to do the compression explicitly with the GZipOutputStream but I couldn't get the response from the server in a client side. I tried to add some headers to the response of websocket request like Sec-Websocket-Extensions: permessage-deflate, but in the end I couldn't add this header manually.

  • for testing except chrome browser I also use wireshark
  • java 1.8 from amazon
  • Server name Tomcat9, Payara5
@jfarcand
Copy link
Member

@repbl444 can you share a simple test cas on Github?

@repbl444
Copy link
Author

repbl444 commented Oct 19, 2022

I am a newby in atmosphere so maybe I do not understand something. I thought that atmosphere has something to compress messages through websocket , I just should put a flag (true) . By this flag I mean to activate for example some extensions. And JSR356 looked like the one. For me it is necessary to run it on glassfish5(payara5) and I did there some configuration like
<protocols> <protocol name="http-listener-1"> <http comet-support-enabled="true" compressable-mime-type="application/javascript,application/json" compression-min-size-bytes="1024" max-connections="250" default-virtual-server="server" compression="on"> <file-cache></file-cache> </http> <ssl></ssl> </protocol> <protocol name="http-listener-2" security-enabled="true"> <http comet-support-enabled="true" compressable-mime-type="application/javascript,application/json" compression-min-size-bytes="1024" max-connections="250" default-virtual-server="server" compression="on"> <file-cache></file-cache> </http> <ssl classname="com.sun.enterprise.security.ssl.GlassfishSSLImpl" cert-nickname="s1as"></ssl> </protocol> <protocol name="admin-listener"> <http encoded-slash-enabled="true" max-connections="250" default-virtual-server="__asadmin"> <file-cache></file-cache> </http> </protocol> </protocols>
maybe just for streaming transport I thought it should work okay
https://github.com/repbl444/atmosphere-samples/tree/master/samples/meteor-chat
I did a commit in the fork. There I have some changes in web.xml
I just didn't find an article how to activate compression with atmosphere websockets/streaming.
Maybe I did something wrong and I need some advice, thank you in advance

@repbl444
Copy link
Author

repbl444 commented Oct 21, 2022

I also add a gzip compression to the application with Spring MVC https://github.com/repbl444/SpringMVCtestCompression
compressable-mime-type="application/javascript,application/json" compression-min-size-bytes="1024" compression="on"
in payara5 in domain.xml like I did for the meteor-chat. After enabling gzip compression I can find some info, that it works
and see that the size of the messages is really decreased.
image
As I understand right for websocket we also can use headers like Content-Encoding or Sec-Websocket-Extensions
with the value permessage-deflate or gzip. But I did get how to turn them on.
But for now I have this Response from the server side
image
and this request
image
Could you give me an advice please?
Can I turn on a compression for websocket messages with just payara5 configuration or something with atmosphere or maybe both?

@jfarcand
Copy link
Member

@repbl444 Salut. I don't have time right now to take a look, but I suspect you need to use Nettosphere if you want to use compression with Atmosphere. I haven't implemented the support for other server. Sorry! I will be happy to integrate your work if you take the Atmosphere code and implement it.

@repbl444
Copy link
Author

Got it, thank you

@repbl444
Copy link
Author

repbl444 commented Nov 2, 2022

Can you give me some hints please which classes/configurations needs to be changed in atmosphere to support compression with glassfish? Thanks in advance.

@jfarcand
Copy link
Member

jfarcand commented Nov 3, 2022

@repbl444 Just write an AtmosphereInterceptor and check when the transport is websocket, compress it using an open source library.

@repbl444
Copy link
Author

repbl444 commented Nov 10, 2022

Hello, thank you for hints. Now I use atmosphere http streaming instead of websocket with a gzip compression. It needs only a configuration in a server.
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" compression="on" compressionMinSize="1024" compressableMimeType="text/html,text/plain,text/css,application/javascript,application/json" />
This is only thing I need to add for tomcat9 to have a compressed messages from a scheduler I have in my example
https://github.com/repbl444/spring-atmosphere-chat-example. But I need to run it in payara5/glassfish5. It works correctly in payara only when without compression. When in domain.xml I turn the compression on, the streaming connection can not be created.
<protocol name="http-listener-1"> <http comet-support-enabled="true" compressable-mime-type="text/html,text/plain,text/css,application/javascript,application/json" compression-min-size-bytes="128" max-connections="250" default-virtual-server="server"> <file-cache></file-cache> </http> <ssl></ssl> </protocol>
Configuration for domain.xml

Glassfish says that it supports the compression when the version of http/1.1 and I have the same
image

Maybe it is a bug or maybe I missed something. Could you give your opinion about that please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants