my application is logging a shitload of video and i2c sensor data into a disk file - as fast as possible. Currently I am converting everything to bytes and i am writing with a BufferedOutputStream. @Siguza was kind enough to suggest looking into a GZIPOutputStream to accomplish the deed. i was wondering whether you had any thoughts on performance issues pro and con ... i am thinking the processor is way ahead and the disk write is the bottleneck - so i am hoping that compressing on the fly via a GZIPOutputStream before the write might be a good strategy. any thoughts on this greatly welcome.
Added: in response to comments ...
turns out zipping is not that processor expensive ... and the way i had asked the original question was not great, as erwin rightly pointed out. the question about zipping performance is not between a BufferedOutputStream and a GZIPOutputStream ... both zipped and unzipped streams need to be wrapped into a BufferedOutputStream, but how much of a cost is added if the original FileOutputStream is wrapped in a GZIPOutputStream first before it is wrapped in a BufferedOutputStream. here is the answer. I am using code
byte[] bs = RHUtilities.toByteArray((int)1);
boolean zipped = false;
FileOutputStream fos = new FileOutputStream(datFile);
BufferedOutputStream bos = null;
if (zipped) {
GZIPOutputStream gz = new GZIPOutputStream(fos);
bos = new BufferedOutputStream(gz);
} else
bos = new BufferedOutputStream(fos);
long startT = System.currentTimeMillis();
for (int i=0; i<1000000; i++)
bos.write(bs);
bos.flush();
System.out.println(System.currentTimeMillis()-startT);
bos.close();
my 2012 macpro laptop does a write of 1M ints with
zipped=true in 38ms - filesize 4MB
zipped=false in 21ms - fileSize 4KB
and, yes, i like the compression :-)
read perfomance is almost identical 83 vs 86ms between
FileInputStream fin = new FileInputStream(datFile);
and
GZIPInputStream gin = new GZIPInputStream(new FileInputStream(datFile));
all good ...