apache / apache/lucene

Remove synchronized from high-contention methods on RAMFile [LUCENE-7778]

Open
#8,829 7 comments 0 reactions 0 assignees View on GitHub
legacy-jira-priority:Minor module:core/store type:enhancement
Dominant language
Java
Stars
3.6k
Forks
1.4k
Avg merge
2d 11h
Merged PRs (30d)
88

Description

When benchmarking RAMDirectory access via multiple threads the methods `RAMFile::numBuffers` and `RAMFile::getBuffer` show up blocking threads fairly frequently

By removing the `synchronized` keyword from these methods our internal benchmarks show a 2x performance increase under concurrent load.

I don't think removing `synchronized` from these methods is a problem as they are read-only and write access to these fields is not synchronized. #3853 also implies that some ofthe locking on RAMDirectory is not necessary

---
Migrated from [LUCENE-7778](https://issues.apache.org/jira/browse/LUCENE-7778) by Steve Mason (@spmason), updated May 17 2017

Contributor guide

Open the contributing guide

Research direction

Locate the RAMFile class and inspect numBuffers and getBuffer, then trace their callers and the unsynchronized field writes. Compare the behavior with the existing RAMDirectory locking and run the concurrent-access benchmarks mentioned in the issue; done means the methods no longer block unnecessarily without introducing unsafe reads.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend, performance
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.