[ https://issues.apache.org/jira/browse/CASSANDRA-20804?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18011730#comment-18011730 ]
Dmitry Konstantinov edited comment on CASSANDRA-20804 at 8/3/25 10:04 PM: -------------------------------------------------------------------------- Additional optimization to reduce ReplicaLayout.forTokenWriteLiveAndDown cost more: we can identify in advance if there is no pending endpoints and do not lookup endpoints for twice here: {code} natural = forNonLocalStrategyTokenRead(dataPlacement, token); pending = forNonLocalStrategyTokenWrite(dataPlacement, token).without(natural.endpoints()); {code} https://github.com/apache/cassandra/pull/4282/commits/598a1c10dfab3f88f2deb071536df4c782ef83fd !5.1_change2_cpu.png|width=700! [^repl2_cpu.html] was (Author: dnk): Additional optimization to reduce ReplicaLayout.forTokenWriteLiveAndDown cost more: we can identify in advance if there is no pending endpoints and do not lookup endpoints for twice here: {code} natural = forNonLocalStrategyTokenRead(dataPlacement, token); pending = forNonLocalStrategyTokenWrite(dataPlacement, token).without(natural.endpoints()); {code} !5.1_change2_cpu.png|width=700! [^repl2_cpu.html] > Optimize DataPlacement lookup by ReplicationParams > -------------------------------------------------- > > Key: CASSANDRA-20804 > URL: https://issues.apache.org/jira/browse/CASSANDRA-20804 > Project: Apache Cassandra > Issue Type: Improvement > Components: Consistency/Coordination, Transactional Cluster Metadata > Reporter: Dmitry Konstantinov > Assignee: Dmitry Konstantinov > Priority: Normal > Fix For: 5.x > > Attachments: 5.1_change2_cpu.png, 5.1_repl_cpu.html, > image-2025-07-30-18-39-40-063.png, image-2025-08-02-17-47-11-156.png, > repl2_cpu.html > > Time Spent: 10m > Remaining Estimate: 0h > > When we execute a plain write to identify replicas we do several lookups from > ClusterMetadata.placements map using ReplicationParams as a map key. > Equals and hashcode for ReplicationParams objects are not very cheap, so > there is a noticible overhead for this logic in CPU profile (0.77% of overall > CPU usage for a plain write Cassandra stress test): > !image-2025-07-30-18-39-40-063.png|width=700! > To reduce it the following optimisations can be applied: > # Avoid double lookup of the same DataPlacement in > forNonLocalStrategyTokenRead and forNonLocalStrategyTokenWrite methods > # Memorize hashCode value > # Deduplicate ReplicationParams to use the same objects in DataPlacements > and KeyspaceMetadata to use the fast == path in the equals > The last two optimizations are safe because ReplicationParams is immutable. > Note: it is related to TCM logic, so it is trunk only issue. -- This message was sent by Atlassian Jira (v8.20.10#820010) --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org For additional commands, e-mail: commits-h...@cassandra.apache.org