Skip to content

AtomicLong.updateAndGet()超级费CPU,并发一多就100% #86

@yangxuanjia

Description

@yangxuanjia

Screenshot from 2023-03-03 15-26-20
Screenshot from 2023-03-03 15-27-17

原来:

// spin get next available cursor
long currentCursor = cursor.get();
long nextCursor = cursor.updateAndGet(old -> old == tail.get() ? old : old + 1);

// trigger padding in an async-mode if reach the threshold
long currentTail = tail.get();

改成下面这样是否可以???

// spin get next available cursor
long currentCursor = cursor.get();
long currentTail = tail.get();

long nextCursor = currentCursor;
if (currentCursor != currentTail) {
    nextCursor = cursor.incrementAndGet();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions