Skip to content

Conversation

@315157973
Copy link
Contributor

Motivation

Cache Eviction is executed every 100ms by default, and the frequency is very high. I have observed that it produces a lot of garbage
image

The optimized memory is as follow:
image

Modifications

1)When there is no cache, no longer check
2)Avoid traversing all cursors

Documentation

no-need-doc

@lhotari
Copy link
Member

lhotari commented Sep 15, 2021

There's a related problem report about the garbage in #9958 .

lhotari
lhotari previously approved these changes Sep 15, 2021
Copy link
Member

@lhotari lhotari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @315157973 !

}

return smallest;
return (PositionImpl) (activeCursors.getSlowestReader()).getReadPosition();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's also a method called ManagedCursorContainer.getSlowestReaderPosition(), could that have been used?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks that is uses getMarkDeletedPosition() so it's probably different than activeCursors.getSlowestReader().getReadPosition()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, now it seems to ignore the non-durable cursor

@lhotari lhotari self-requested a review September 15, 2021 15:45
@lhotari lhotari dismissed their stale review September 15, 2021 15:46

code changes, I'm unsure about the solution.

@315157973
Copy link
Contributor Author

@codelipenghui @hangc0276 PTAL

@315157973
Copy link
Contributor Author

315157973 commented Sep 16, 2021

profile-0.jfr.zip
profile.jfr.zip

Here is the JFR record

@codelipenghui codelipenghui added this to the 2.9.0 milestone Sep 18, 2021
@Anonymitaet Anonymitaet added the doc-not-needed Your PR changes do not impact docs label Sep 22, 2021
@315157973
Copy link
Contributor Author

jfr of the latest code
profile-78.jfr.zip

image

private final StampedLock rwLock = new StampedLock();

// Used to keep track of the slowest non-durable cursor.
private final ArrayList<Item> heapForNonDurableCursors = Lists.newArrayList();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks if we want the track the slowest position for the non-durable cursor, it's more easier to maintain durableCursorContainer and nonDurableCursorContainer in the ManagedLedger? so that we don't need to change the implementation of the ManageCursorContainer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@315157973
Copy link
Contributor Author

@codelipenghui PTAL

@codelipenghui
Copy link
Contributor

@merlimat Please help review the PR, thanks.

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great

Copy link
Contributor

@hangc0276 hangc0276 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great job!

@315157973
Copy link
Contributor Author

Is it ready to merge ?

@eolivelli eolivelli merged commit 0c22e0f into apache:master Sep 30, 2021
codelipenghui pushed a commit that referenced this pull request Oct 6, 2021
@codelipenghui codelipenghui added the cherry-picked/branch-2.8 Archived: 2.8 is end of life label Oct 6, 2021
codelipenghui pushed a commit that referenced this pull request Dec 11, 2021
@codelipenghui codelipenghui added the cherry-picked/branch-2.7 Archived: 2.7 is end of life label Dec 11, 2021
bharanic-dev pushed a commit to bharanic-dev/pulsar that referenced this pull request Mar 18, 2022
aloyszhang pushed a commit to aloyszhang/pulsar that referenced this pull request Aug 5, 2022
…uest !72)


Squash merge branch 'OptimizeMemoryCache' into '2.8.1'
Fixes #<xyz>

### Motivation
优化cache内存使用
lhotari added a commit to lhotari/pulsar that referenced this pull request Aug 23, 2022
…on of active cursors when cacheEvictionByMarkDeletedPosition=false

Fixes apache#16054

- calculate the sorted list of when a read position gets updated
- this resolves apache#9958 in a proper way
  - apache#12045 broke the caching solution as explained in apache#16054
lhotari added a commit to lhotari/pulsar that referenced this pull request Aug 25, 2022
… active cursors when cacheEvictionByMarkDeletedPosition=false

Fixes apache#16054

- calculate the sorted list of when a read position gets updated
- this resolves apache#9958 in a proper way
  - apache#12045 broke the caching solution as explained in apache#16054
- remove invalid tests
- fix tests
- add more tests to handle corner cases
lhotari added a commit to lhotari/pulsar that referenced this pull request Aug 26, 2022
… active cursors when cacheEvictionByMarkDeletedPosition=false

Fixes apache#16054

- calculate the sorted list of when a read position gets updated
- this resolves apache#9958 in a proper way
  - apache#12045 broke the caching solution as explained in apache#16054
- remove invalid tests
- fix tests
- add more tests to handle corner cases
lhotari added a commit that referenced this pull request Aug 31, 2022
…sors (#17273)

* [fix][broker] Fix broken build caused by conflict between #17195 and #16605

- #17195 changed the method signature that #16605 depended upon

* [fix][broker] Keep sorted list of cursors ordered by read position of active cursors when cacheEvictionByMarkDeletedPosition=false

Fixes #16054

- calculate the sorted list of when a read position gets updated
- this resolves #9958 in a proper way
  - #12045 broke the caching solution as explained in #16054
- remove invalid tests
- fix tests
- add more tests to handle corner cases

* Address review comment

* Handle durable & non-durable in the correct way

* Fix cache tests since now entries get evicted reactively

* Address review comment about method names

* Change signature for add method so that position must be passed

- this is more consistent with cursorUpdated method where the position is passed

* Update javadoc for ManagedCursorContainer

* Address review comment

* Simplify ManagedCursorContainer

* Clarify javadoc

* Ensure that cursors are tracked by making sure that initial position isn't null unintentionally

* Prevent race in updating activeCursors
Technoboy- pushed a commit that referenced this pull request Oct 31, 2022
…sors (#17273)

* [fix][broker] Fix broken build caused by conflict between #17195 and #16605

- #17195 changed the method signature that #16605 depended upon

* [fix][broker] Keep sorted list of cursors ordered by read position of active cursors when cacheEvictionByMarkDeletedPosition=false

Fixes #16054

- calculate the sorted list of when a read position gets updated
- this resolves #9958 in a proper way
  - #12045 broke the caching solution as explained in #16054
- remove invalid tests
- fix tests
- add more tests to handle corner cases

* Address review comment

* Handle durable & non-durable in the correct way

* Fix cache tests since now entries get evicted reactively

* Address review comment about method names

* Change signature for add method so that position must be passed

- this is more consistent with cursorUpdated method where the position is passed

* Update javadoc for ManagedCursorContainer

* Address review comment

* Simplify ManagedCursorContainer

* Clarify javadoc

* Ensure that cursors are tracked by making sure that initial position isn't null unintentionally

* Prevent race in updating activeCursors
congbobo184 pushed a commit that referenced this pull request Nov 17, 2022
…sors (#17273)

* [fix][broker] Fix broken build caused by conflict between #17195 and #16605

- #17195 changed the method signature that #16605 depended upon

* [fix][broker] Keep sorted list of cursors ordered by read position of active cursors when cacheEvictionByMarkDeletedPosition=false

Fixes #16054

- calculate the sorted list of when a read position gets updated
- this resolves #9958 in a proper way
  - #12045 broke the caching solution as explained in #16054
- remove invalid tests
- fix tests
- add more tests to handle corner cases

* Address review comment

* Handle durable & non-durable in the correct way

* Fix cache tests since now entries get evicted reactively

* Address review comment about method names

* Change signature for add method so that position must be passed

- this is more consistent with cursorUpdated method where the position is passed

* Update javadoc for ManagedCursorContainer

* Address review comment

* Simplify ManagedCursorContainer

* Clarify javadoc

* Ensure that cursors are tracked by making sure that initial position isn't null unintentionally

* Prevent race in updating activeCursors

(cherry picked from commit 856ef15)
congbobo184 pushed a commit that referenced this pull request Dec 7, 2022
…sors (#17273)

* [fix][broker] Fix broken build caused by conflict between #17195 and #16605

- #17195 changed the method signature that #16605 depended upon

* [fix][broker] Keep sorted list of cursors ordered by read position of active cursors when cacheEvictionByMarkDeletedPosition=false

Fixes #16054

- calculate the sorted list of when a read position gets updated
- this resolves #9958 in a proper way
  - #12045 broke the caching solution as explained in #16054
- remove invalid tests
- fix tests
- add more tests to handle corner cases

* Address review comment

* Handle durable & non-durable in the correct way

* Fix cache tests since now entries get evicted reactively

* Address review comment about method names

* Change signature for add method so that position must be passed

- this is more consistent with cursorUpdated method where the position is passed

* Update javadoc for ManagedCursorContainer

* Address review comment

* Simplify ManagedCursorContainer

* Clarify javadoc

* Ensure that cursors are tracked by making sure that initial position isn't null unintentionally

* Prevent race in updating activeCursors

(cherry picked from commit 856ef15)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/broker cherry-picked/branch-2.7 Archived: 2.7 is end of life cherry-picked/branch-2.8 Archived: 2.8 is end of life doc-not-needed Your PR changes do not impact docs release/2.7.4 release/2.8.2 release/2.9.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants