kezhenxu94 commented on a change in pull request #2930: One more time for
heigher performance
URL: https://github.com/apache/skywalking/pull/2930#discussion_r296583740
##########
File path:
apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/common/AtomicRangeInteger.java
##########
@@ -20,28 +20,32 @@
package org.apache.skywalking.apm.commons.datacarrier.common;
import java.io.Serializable;
-import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicIntegerArray;
/**
- * Created by wusheng on 2016/10/25.
+ * Created by lkxiaolou
*/
public class AtomicRangeInteger extends Number implements Serializable {
private static final long serialVersionUID = -4099792402691141643L;
- private AtomicInteger value;
+ private AtomicIntegerArray values;
+
+ private static final int VALUE_OFFSET = 15;
+
private int startValue;
private int endValue;
public AtomicRangeInteger(int startValue, int maxValue) {
- this.value = new AtomicInteger(startValue);
+ this.values = new AtomicIntegerArray(31);
Review comment:
> * 12 bytes(in OS 64-bits) for the array ref
The memory address of the array reference isn't necessarily next to the 31
`int`s, the reference can be allocated at another memory block far away from
the 31 `int`s, so it's unnecessary to take it into consideration.
> 4 bytes(int) * 13(size)
I think you had missed the same thing as I had, see
https://github.com/apache/skywalking/pull/2930#discussion_r296446602
consider the cache line as a sliding window (of size 64 in 64-bits OS and
size 32 in 32-bits OS), we must ensure that no matter where the window slides
to, there must be only one `value` that will change in the window, and the
remainings are `placeholders` that are never modified, to ensure that the cache
line only contains our desired `value` that is changing.
```text
15 * 4 = 60
15 * 4 = 60
+-------------------------------------------------+
+----------------------------------------------------------+
| | (4 bytes) |
|
+-------------------------------------------------+ value
+----------------------------------------------------------+
+--------------------------------------------------------------------+
| |
+--------------------------------------------------------------------+
cache line(sliding window) 64
+---------------------------->
slide
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services