We are going to write a feature on my system that will require a very massive user http post and http response, probably millions of requests/response with just some bytes each ( sending and getting with ajax and json )
我们将在我的系统上编写一个特性,它将需要大量的用户http post和http响应,可能需要数百万个请求/响应,每个请求/响应只有一些字节(使用ajax和json发送和获取)
but that's not enough I need to find a way to compress the data with java script and decompress on the server side ( .net or java servlets ) and also compress on the server and decompress with javascript.
但这还不够,我需要找到一种方法,用java脚本压缩数据,在服务器端(.net或java servlet)解压,在服务器端压缩数据,并使用javascript解压。
It seems silly save such bytes, but I want to be prepared for the worst.
保存这些字节看起来很傻,但我想做最坏的打算。
Any directions? just post what you think, let's share our thoughts
有方向吗?发布你的想法,分享我们的想法
thanks
谢谢
Ed
艾德
5 个解决方案
#1
1
In Java you could use the java.util.zip
package which should provide you with compress-/decompress methods.
在Java中,您可以使用Java .util。zip包应该为您提供压缩/解压缩方法。
For JavaScript I found this tutorial. Or you could implement your own method by replacing all unicode characters of the byte-stream like this:
对于JavaScript,我找到了本教程。或者您可以实现自己的方法,替换字节流的所有unicode字符,如下所示:
Your message:AABCCC
Unicode Bytes: 0x41 0x00 0x41 0x00 0x42 0x00 0x43 0x00 0x43 0x00 0x43 0x00
compressed by leaving out the 0x00 : 0x41 0x41 0x42 0x43 0x43 0x43
even more by leaving out doubles: 2 0x41 1 0x42 3 0x43
您的消息:AABCCC Unicode字节:0x41 0x00 0x41 0x00 0x42 0x00 0x42 0x00 0x43 0x43 0x00 0x43 0x00 0x43 0x43 0x00 0x43 0x43 0x43 0x43 0x43 0x00 0x43 0x00通过省略0x43: 0x00: 0x41 0x41 0x42 0x42 0x43 0x43 0x43 0x43 0x43 0x43 0x43 0x43 0x43 0x43 0x43而压缩
Even though it doesn't look very impressive right now, there might be one or two requests that could profit from this compression. Although it is really important for the algorithm to be very effective and sufficient. Since you are talking about 'millions' of requests. One big request could profit from this compression, but many small requests could be very inefficient.
虽然现在看起来不太令人印象深刻,但是可能有一两个请求可以从这种压缩中获利。尽管算法的有效性和充分性非常重要。因为你说的是“数百万”的请求。一个大的请求可以从这个压缩中获益,但是许多小的请求可能非常低效。
Sorry I can't provide you with a complete solution, but maybe this brings you a little closer.
对不起,我不能给你一个完整的解决方案,但这可能会让你更接近。
#2
1
Is a server-level implementation of zlib compression not good enough for your use case? That'd be the most simple and reliable way to get compression working. All the most common web servers and browsers support zlib compression out of the box.
对于您的用例来说,zlib压缩的服务器级实现还不够好吗?这将是使压缩工作最简单和可靠的方法。所有最常见的web服务器和浏览器都支持开箱即用的zlib压缩。
#3
1
You can use HTTP Compression suppoerted by major web servers, app servers and browsers. While you do that, note that IE has historically been very buggy in that area, so make sure that it works in multiple versions of IE. For apache, you can use mod_deflate. Jetty & Tomcat have their own versions of a GZIP filter. Compressing/Decompressing in Javascript will be cumbersome. I am not aware of any libraries available in JS that can help you.
您可以使用主要web服务器、应用服务器和浏览器支持的HTTP压缩。当你这么做的时候,请注意IE在这一领域一直存在很大的问题,所以要确保它在多个版本的IE中工作。对于apache,可以使用mod_deflate。Jetty和Tomcat有自己的GZIP过滤器版本。在Javascript中压缩/解压将会很麻烦。我不知道JS中有什么库可以帮助您。
#4
1
Performance questions require you to try and measure to get any reasonable answer.
性能问题要求您尝试和度量以获得任何合理的答案。
In your case I would carefully look at raw message and see where bytes are - I bet that for tiny data packets most of the bytes would be in headers, so compression of content will give you no benefit. It is your system - look at your requests and see where you can get decrease size of packets.
在您的情况下,我将仔细查看原始消息,并查看字节的位置——我打赌,对于很小的数据包,大多数字节都是在头文件中,因此压缩内容将不会给您带来任何好处。它是你的系统——查看你的请求,看看哪里可以减少数据包的大小。
Note that often you need to send user's authentication with the request - as result your request will have fixed size, usually non-compressible chunk of data in it.
注意,您经常需要用请求发送用户的身份验证——因此您的请求将具有固定的大小,通常是不可压缩的数据块。
#5
0
You could install a compression filter and have that handle it for you:
你可以安装一个压缩过滤器,让它为你处理:
http://code.google.com/p/webutilities/source/browse/trunk/src/com/googlecode/webutilities/filters/GZIPCompressionFilter.java?spec=svn39&r=39
#1
1
In Java you could use the java.util.zip
package which should provide you with compress-/decompress methods.
在Java中,您可以使用Java .util。zip包应该为您提供压缩/解压缩方法。
For JavaScript I found this tutorial. Or you could implement your own method by replacing all unicode characters of the byte-stream like this:
对于JavaScript,我找到了本教程。或者您可以实现自己的方法,替换字节流的所有unicode字符,如下所示:
Your message:AABCCC
Unicode Bytes: 0x41 0x00 0x41 0x00 0x42 0x00 0x43 0x00 0x43 0x00 0x43 0x00
compressed by leaving out the 0x00 : 0x41 0x41 0x42 0x43 0x43 0x43
even more by leaving out doubles: 2 0x41 1 0x42 3 0x43
您的消息:AABCCC Unicode字节:0x41 0x00 0x41 0x00 0x42 0x00 0x42 0x00 0x43 0x43 0x00 0x43 0x00 0x43 0x43 0x00 0x43 0x43 0x43 0x43 0x43 0x00 0x43 0x00通过省略0x43: 0x00: 0x41 0x41 0x42 0x42 0x43 0x43 0x43 0x43 0x43 0x43 0x43 0x43 0x43 0x43 0x43而压缩
Even though it doesn't look very impressive right now, there might be one or two requests that could profit from this compression. Although it is really important for the algorithm to be very effective and sufficient. Since you are talking about 'millions' of requests. One big request could profit from this compression, but many small requests could be very inefficient.
虽然现在看起来不太令人印象深刻,但是可能有一两个请求可以从这种压缩中获利。尽管算法的有效性和充分性非常重要。因为你说的是“数百万”的请求。一个大的请求可以从这个压缩中获益,但是许多小的请求可能非常低效。
Sorry I can't provide you with a complete solution, but maybe this brings you a little closer.
对不起,我不能给你一个完整的解决方案,但这可能会让你更接近。
#2
1
Is a server-level implementation of zlib compression not good enough for your use case? That'd be the most simple and reliable way to get compression working. All the most common web servers and browsers support zlib compression out of the box.
对于您的用例来说,zlib压缩的服务器级实现还不够好吗?这将是使压缩工作最简单和可靠的方法。所有最常见的web服务器和浏览器都支持开箱即用的zlib压缩。
#3
1
You can use HTTP Compression suppoerted by major web servers, app servers and browsers. While you do that, note that IE has historically been very buggy in that area, so make sure that it works in multiple versions of IE. For apache, you can use mod_deflate. Jetty & Tomcat have their own versions of a GZIP filter. Compressing/Decompressing in Javascript will be cumbersome. I am not aware of any libraries available in JS that can help you.
您可以使用主要web服务器、应用服务器和浏览器支持的HTTP压缩。当你这么做的时候,请注意IE在这一领域一直存在很大的问题,所以要确保它在多个版本的IE中工作。对于apache,可以使用mod_deflate。Jetty和Tomcat有自己的GZIP过滤器版本。在Javascript中压缩/解压将会很麻烦。我不知道JS中有什么库可以帮助您。
#4
1
Performance questions require you to try and measure to get any reasonable answer.
性能问题要求您尝试和度量以获得任何合理的答案。
In your case I would carefully look at raw message and see where bytes are - I bet that for tiny data packets most of the bytes would be in headers, so compression of content will give you no benefit. It is your system - look at your requests and see where you can get decrease size of packets.
在您的情况下,我将仔细查看原始消息,并查看字节的位置——我打赌,对于很小的数据包,大多数字节都是在头文件中,因此压缩内容将不会给您带来任何好处。它是你的系统——查看你的请求,看看哪里可以减少数据包的大小。
Note that often you need to send user's authentication with the request - as result your request will have fixed size, usually non-compressible chunk of data in it.
注意,您经常需要用请求发送用户的身份验证——因此您的请求将具有固定的大小,通常是不可压缩的数据块。
#5
0
You could install a compression filter and have that handle it for you:
你可以安装一个压缩过滤器,让它为你处理:
http://code.google.com/p/webutilities/source/browse/trunk/src/com/googlecode/webutilities/filters/GZIPCompressionFilter.java?spec=svn39&r=39