问题
I'm putting some bigger JSON values in my caching layer (redis), and I think they could use some compression to cut down my memory usage a bit.
Which compression modules for node.js do you use? For some reason everything that's listed on the joyent/node Modules wiki looks fishy - either 404s, no commits for more than a year, very few people watching, or open reports of memory leaks.
Snappy looks nice, but I'd rather go for something more portable.
I'd naturally prefer an async compression/decompression API over a blocking one, but I'm also curious if you think it makes a big difference for low compression levels.
Thanks in advance for your replies!
EDIT:
About portability: what I really meant is that the module can be installed via npm
and has no external dependencies that are not present on generic *NIX setups.
Why? Because certain PaaS setups (currently only heroku's celadon-cedar to my knowledge, but perhaps more in the future) don't provide traditional admin access to the instance environment via ssh or the like, and the only way to bring in dependencies is via npm
.
Ideally, the module should also run on cygwin.
So what would you use?
回答1:
When you say 'more portable' I assume you're referring to the C++ code with snappy. Unfortunately a native javascript implementation of most compression algorithms would be an order of magnitude slower than a native C/C++ implementation, which is why nearly all of the node compression libraries use it. Snappy is extremely portable (I've built it on Solaris, Linux and OSX) and fairly active. I would strongly recommend it over anything else.
回答2:
There are optimizations you can try before adding compression overhead. See the documentation on memory optimization.
来源:https://stackoverflow.com/questions/6387378/compression-in-node-js