[Java] Memory leak when use VectorSchemaSlice slice
- Linguagem predominante
- Java
- Estrelas
- 94
- Forks
- 152
- Merge médio
- 3d 16h
- PRs com merge (30d)
- 11
Descrição
### Describe the usage question you have. Please include as many useful details as possible.
In my Flink process function, I receive serialized VectorSchemaRoot data which needs to be deserialized for further processing. As I need to operate on it row by row, I utilized the slice function. However, this approach can lead to an increase in direct memory usage which in turn reduces the heap memory space in Flink. Ultimately, this can result in an Out Of Memory (OOM) exception as the heap memory space becomes insufficient. However, if I serialize the sliced VectorSchemaRoot and pass it as a parameter to the downstream function, which then deserializes it again, there will be no more OOM issues.
```
public void processElement(I value, ProcessFunction.Context context, Collector collector) throws Exception {
if (this.writerHelper == null) {
initWriterHelper();
}
reader = new ArrowStreamReader(new ByteArrayInputStream((byte[]) value), ArrowUtil.rootAllocator);
try {
while (reader.loadNextBatch()) {
VectorSchemaRoot vsr = reader.getVectorSchemaRoot();
int rowCount = vsr.getRowCount();
for (int i = 0; i < rowCount; i++) {
//split to row
VectorSchemaRoot row = vsr.slice(i, 1);
// this.writerHelper.write(row); This approach can result in a memory leak, whereas the following method will not.
ByteArrayOutputStream out = new ByteArrayOutputStream();
ArrowStreamWriter writer =
new ArrowStreamWriter(row, null, Channels.newChannel(out));
writer.start();
writer.writeBatch();
this.writerHelper.write(out.toByteArray());
row.clear();
row.close();
}
vsr.clear();
vsr.close();
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
reader.close();
}
}```
### Component(s)
Java
Guia de contribuição
Direção de pesquisa
Comece pelo exemplo de processElement, especialmente por VectorSchemaRoot.slice(i, 1) e pelas chamadas row.clear()/row.close(). Reproduza o crescimento da memória direta ao gravar linhas fatiadas por meio de writerHelper e depois compare-o com o caminho de serialização e desserialização. Considera-se concluído quando o caminho de linhas fatiadas não causar mais o crescimento de memória relatado nem OOM.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- java
- Domínio
- data
- Tipo de issue
- Bug
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Status de atividade
- Estagnada
- Clareza
- Precisa de esclarecimento
- Facilidade para iniciantes
- 30/100