PrestoS3OutputStream writes byte-by-byte: missing write(byte[], int, int) override makes S3 uploads CPU-bound
Your Environment
- Presto version used: presto-hive 0.272, as bundled in Apache Flink's flink-s3-fs-presto 2.2.1. The class is unchanged on master.
- Storage (HDFS/S3/GCS..): S3
- Data source and connector used: PrestoS3FileSystem, used through Flink for checkpoint storage
- Deployment (Cloud or On-prem): Cloud (AWS EKS), JDK 17
Expected Behavior
PrestoS3OutputStream.write(byte[], int, int) passes the whole buffer to the underlying stream.
Current Behavior
PrestoS3FileSystem.PrestoS3OutputStream extends java.io.FilterOutputStream and overrides only close(). FilterOutputStream.write(byte[], int, int) is documented to call write(int) once per byte, so every buffer is copied into the temp file's BufferedOutputStream one byte at a time.
In a CPU profile of an ~18 GB write through this stream, 84% of process CPU was self time in java.io.FilterOutputStream.write(byte[], int, int), making the write CPU-bound.
Possible Solution
Override the array write in PrestoS3OutputStream:
@Override
public void write(byte[] b, int off, int len)
throws IOException
{
out.write(b, off, len);
}#22424 adds overrides like this as part of a larger change, but it has been inactive since 2024-08.
Steps to Reproduce
- Create a
PrestoS3FileSystemagainst any S3 bucket. - Open a file with
create(...)and write a few GB in 4 KB or largerwrite(byte[], int, int)calls. - Profile CPU during the writes, before
close()starts the upload: most of it is inFilterOutputStream.write(byte[], int, int).
Context
Flink's S3 Presto filesystem uses this class for checkpoints and savepoints. Large uploads become CPU-bound.
Source: prestodb/presto