Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #61: Add Phaser in favor of a custom count and lock solution to Access and BufferLeaseImpl classes #70

Closed
wants to merge 17 commits into from

Conversation

eemhu
Copy link
Contributor

@eemhu eemhu commented Feb 20, 2024

#61

Note: This PR is a draft

@eemhu eemhu marked this pull request as ready for review February 21, 2024 08:19
phaser.arriveAndDeregister();
}

public boolean closed() {
Copy link
Member

Choose a reason for hiding this comment

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

is closed() extra?

finally {
lock.unlock();
}
phaser.arriveAndDeregister();
}

@Override
public boolean isRefCountZero() {
Copy link
Member

Choose a reason for hiding this comment

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

this must be changed so that it checks if the phaser isTerminated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix 334d130

@@ -28,13 +29,8 @@ public long id() {

@Override
public long refs() {
Copy link
Member

Choose a reason for hiding this comment

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

this should be removed or at least marked as unreliable because phaser is a lock free structure so ref count should be only used for debug logging

public final class Rental implements AutoCloseable, Consumer<Lease>, Supplier<Lease> {

private final Phaser phaser;
private boolean closed;
Copy link
Member

Choose a reason for hiding this comment

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

this is extra, should return phaser.isTerminated() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

return phaser.isTerminated: 334d130

@@ -1,12 +1,12 @@
package com.teragrep.rlp_03.context.frame.access;
package com.teragrep.rlp_03.context.frame.rental;

public class Lease implements AutoCloseable {
Copy link
Member

Choose a reason for hiding this comment

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

could this be refactored so that it uses a sub-phaser that is registered to the parent?

@kortemik
Copy link
Member

currently is broken, buffer is likely to be contaminated accross the threads:

[pool-9-thread-1] ERROR com.teragrep.rlp_03.context.RelpReadImpl - run() threw
java.lang.IllegalArgumentException: no match for EndOfTransfer character \n
        at com.teragrep.rlp_03.context.frame.function.EndOfTransferFunction.apply(EndOfTransferFunction.java:33)

i suspect the attemptRelease() is broken because clear() is not ensured by happens-before relationship of phaser.isTerminated()

…rk BufferLeaseImpl.refs as unreliable, change Rental.closed() to return phaser.isTerminated
@kortemik
Copy link
Member

there are test failures now

Note: RentalTest contains IllegalStateException assert that does not seem to happen, commented out for now.
@eemhu
Copy link
Contributor Author

eemhu commented Feb 23, 2024

seem to pass tests locally, however "RentalTest contains IllegalStateException assert that does not seem to happen, commented out for now." in 38ec3d0

add sub phaser to Lease

@kortemik
Copy link
Member

kortemik commented Feb 23, 2024 via email

@eemhu
Copy link
Contributor Author

eemhu commented Feb 26, 2024

Regarding BufferLeaseImpl, it might be appropriate to store cleared buffers in the pool and take new Leases (with new phasers) for them when taking out from the pool because phasers are terminated when returning. pe 23. helmik. 2024 klo 10.52 eemhu @.> kirjoitti:

seem to pass tests locally, however "RentalTest contains IllegalStateException assert that does not seem to happen, commented out for now." in 38ec3d0 <38ec3d0> add sub phaser to Lease — Reply to this email directly, view it on GitHub <#70 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGX2OTGWTTALPQULM5SL4LYVBKFRAVCNFSM6AAAAABDQYGTNSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNRQHE2DEMZSHE . You are receiving this because you commented.Message ID: @.
>

@kortemik
Should BufferLeasePool.take() check the polled BufferLease for terminated Phaser and create a new BufferLeaseImpl in that case as well? Currently there is a null-check only.

@kortemik
Copy link
Member

kortemik commented Feb 27, 2024 via email

…rnalOffer, add stub unless phaser was terminated explicitly
@eemhu
Copy link
Contributor Author

eemhu commented Feb 27, 2024

moved phaser to use decorator pattern PhaserDecoratedBufferLease which contains the phaser-related ops and BufferLeaseImplcontains the buffer itself.

@kortemik
Copy link
Member

kortemik commented Feb 27, 2024 via email

@eemhu
Copy link
Contributor Author

eemhu commented Feb 28, 2024

TODO:

  • remove non-atomic operations from Phaser (registeredParties <= 1) etc.
  • remove addRef from bufferleasepool take() so the initial phaser registration counts as it
  • use PhaserDecoration "between" take() and offer(). Phaser is only included when bufferLease is in use. Terminate phaser.

Possibly:

  • use synchronized block instead of lock in buffer()
  • Rental as generic?

@eemhu
Copy link
Contributor Author

eemhu commented Feb 29, 2024

removed comparisons from phaser related classes, added synchronized keyword to bufferLeaseImpl.buffer() and removed lock. Add phaser decoration when polling from queue and remove when adding back to queue.

@eemhu
Copy link
Contributor Author

eemhu commented Feb 29, 2024

Perhaps the offer() method should take in type of PhaserDecoratedBufferLease so we can get rid of instanceof check?

@kortemik
Copy link
Member

kortemik commented Feb 29, 2024 via email

…Lease to BufferContainer. Pool holds BufferContainers and wraps them in BufferLeases while out of the queue.
@eemhu
Copy link
Contributor Author

eemhu commented Feb 29, 2024

Changed PhaserDecoratedBufferLease to be simply called BufferLease, and changed previous BufferLease to be BufferContainer. Now the pool will only contain BufferContainers, and they are wrapped in BufferLeases when taking them out of the pool.

@kortemik
Copy link
Member

kortemik commented Mar 1, 2024

please separate the Access -> Rental to different pr, close this one and open new ones for these both.

@kortemik
Copy link
Member

kortemik commented Mar 1, 2024

running with the a1534ed following agains the ManualPerformanceTest:

/opt/Fail-Safe/rsyslog/rsyslog/bin/tcpflood -p1601 -y -Trelp-plain -m100000000 -c 8 -Y -M "<167>1 2003-03-01T01:00:00.000Z mymachine.example.com tcpflood - tag [tcpflood@32473 MSGNUM="12857358"] msgnum:"

gives

[pool-9-thread-4] ERROR com.teragrep.rlp_03.context.buffer.BufferLeasePool - dirty buffer in pool, terminating

while main branch does not.

@StrongestNumber9 please check the rlp_09 pr tests so that they will reproduce this.

@eemhu please check why this differs from main branch.

this utility is provided from rsyslog project via fail-safe-rsyslog-8.2102.2-1558.fc34.x86_64.rpm, one can obtain it from nexus.

@kortemik kortemik marked this pull request as draft March 1, 2024 11:29
@eemhu
Copy link
Contributor Author

eemhu commented Mar 1, 2024

adding synchronized to BufferLeaseImpl.attemptRelease() method seems to fix it. Perhaps multiple threads try to access attemptRelease() at the same time and thus accessing the buffer as well.

@eemhu
Copy link
Contributor Author

eemhu commented Mar 1, 2024

would make sense considering the main branch version uses a lock there.

@StrongestNumber9
Copy link
Contributor

running with the a1534ed following agains the ManualPerformanceTest:

/opt/Fail-Safe/rsyslog/rsyslog/bin/tcpflood -p1601 -y -Trelp-plain -m100000000 -c 8 -Y -M "<167>1 2003-03-01T01:00:00.000Z mymachine.example.com tcpflood - tag [tcpflood@32473 MSGNUM="12857358"] msgnum:"

gives

[pool-9-thread-4] ERROR com.teragrep.rlp_03.context.buffer.BufferLeasePool - dirty buffer in pool, terminating

while main branch does not.

@StrongestNumber9 please check the rlp_09 pr tests so that they will reproduce this.

@eemhu please check why this differs from main branch.

this utility is provided from rsyslog project via fail-safe-rsyslog-8.2102.2-1558.fc34.x86_64.rpm, one can obtain it from nexus.

Is this still relevant as

adding synchronized to BufferLeaseImpl.attemptRelease() method seems to fix it. Perhaps multiple threads try to access attemptRelease() at the same time and thus accessing the buffer as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants