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

Simpler compression library #4

Closed
funny-falcon opened this issue Mar 16, 2015 · 12 comments
Closed

Simpler compression library #4

funny-falcon opened this issue Mar 16, 2015 · 12 comments

Comments

@funny-falcon
Copy link

I tried to create simple streaming compression library for this project

https://github.com/funny-falcon/go-funlz

Format derived from lzf. It is byte oriented, minimum compressed chunk is 4 bytes, backref window is 4096 bytes. It uses circular buffer of 8096 bytes for buffering uncompressed bytes. It does no output buffering.

Compression is just 1.5 faster than compress/flate, but decompression is up to 2-10 times faster.

@funny-falcon
Copy link
Author

Oh, i forgot to push one commit with tiny refactoring.
It doesn't change interface or stability, but adds some doc and choses faster compression parameters.
So you may already test library.

@valyala
Copy link
Owner

valyala commented Mar 16, 2015

The current version of go-funz hangs gorpc tests - see https://github.com/valyala/gorpc/tree/go-funlz . Could you look into it?

@funny-falcon
Copy link
Author

I've fixed it: looks like without some mark on Flush there is no simple way to prevent blocking on Read when bufio.Reader used. So i introduce Flush mark by stealing 0x00 from literal tag.

@funny-falcon
Copy link
Author

found another error, not fixed yet

@valyala
Copy link
Owner

valyala commented Mar 18, 2015

Now BenchmarkRealApp sometimes fails with the error:

bench_test.go:155: Unexpected response type <nil>

Currently funlz uses more CPU comparing to flate compression and it has worse compression ratio in BenchmarkRealApp:

Client stats for 1K workers, 50K requests:

funlz: 29748 ns/op, 2822578 bytes written, 2829651 bytes read
flate: 27086 ns/op, 770926 bytes written, 849752 bytes read

Client stats for 10K workers, 50K requests:

funlz: 30193 ns/op, 2826387 bytes written, 2847577 bytes read
flate: 27379 ns/op, 732908 bytes written, 804311 bytes read

@funny-falcon
Copy link
Author

Now BenchmarkRealApp sometimes fails with the error:

That is why i closed pull request. I can reproduce data corruption, but not yet found reason.

Currently funlz uses more CPU comparing to flate compression and it has worse compression ratio in BenchmarkRealApp

It has worser ratio cause it is simpler, it is intentional. It could be improved by editing constant and function in doc.go . By the way, what is the size of uncompressed data?

It looks strange that flate uses less CPU. Perhaps it cause of worser compression rate, so more data should be transmitted. I really don't know what to say.

Can we discuss in Russian?

@valyala
Copy link
Owner

valyala commented Mar 19, 2015

By the way, what is the size of uncompressed data?

4743950 bytes read, 4743970 bytes written

It looks strange that flate uses less CPU. Perhaps it cause of worser compression rate, so more data should be transmitted.

No, with flate gorpc transmits 3 times less data comparing to funlz. See the numbers from my previous message.

Can we discuss in Russian?

Да, но тогда многие посетители не поймут, что мы тут обсуждаем )

@funny-falcon
Copy link
Author

It looks strange that flate uses less CPU. Perhaps it cause of worser compression rate, so more data should be transmitted.
No, with flate gorpc transmits 3 times less data comparing to funlz. See the numbers from my previous message.

I mean, funlz has lower compression rate :-)

4743950 bytes read, 4743970 bytes written

So funlz can save ~40%, but flate saves much more... perhaps it is cause of small window and tuning for speed.

I will fix data coruption, and then i'll change format to use 8192 byte window (it will be closer to original lzf). Then will test again :-)

@funny-falcon
Copy link
Author

Good day, Aliaksandr.

I think i've fixed data coruption in https://github.com/funny-falcon/go-funlz , and have fixed a bug which leads to poor compression ratio.
Can you test it again?

And there is number of tuning params in doc.go. Currently they are set for fastest compression, but poorer compression ratio. You may play with them.

Also Writer now has WriteByte method and Reader has ReadByte method - gob encoder/decoder likes presence of such methods. Perhaps it worths to test without wrapping them with bufio.Writer and bufio.Reader.

@funny-falcon funny-falcon reopened this Mar 22, 2015
@valyala
Copy link
Owner

valyala commented Mar 24, 2015

Now go-funlz uses the same CPU as compress/flate , but the compression ratio is still worser with default settings on BenchmarkRealApp:

go-funlz, 1k workers: read: 37 bytes/call, written: 32 bytes/call
go-funlz, 10k workers: read: 24 bytes/call, written: 22 bytes/call
go-funlz, 100k workers: read: 25 bytes/call, written: 24 bytes/call

compress/flate, 1k workers: read: 17 bytes/call, written: 15 bytes/call
compress/flate, 10k workers: read: 16 bytes/call, written: 14 bytes/call
compress/flate, 100k workers: read: 17 bytes/call, written: 16 bytes/call

Also Writer now has WriteByte method and Reader has ReadByte method - gob encoder/decoder likes presence of such methods. Perhaps it worths to test without wrapping them with bufio.Writer and bufio.Reader.

I tried disabling wrapper buffer for go-funlz, but this led to slightly higher CPU usage (from 26us/op to 27us/op).

@valyala
Copy link
Owner

valyala commented Mar 24, 2015

I added debug line in benchmark tests, so you could tune go-funlz - see 5f288fd .

@valyala
Copy link
Owner

valyala commented Jun 8, 2015

Closing the issue, since there is no recent activity on it.

@valyala valyala closed this as completed Jun 8, 2015
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