非恒定内存使用异常

发布于 2024-12-28 06:31:41 字数 5003 浏览 1 评论 0原文

我在打开 MeasureMemory 的情况下进行测试,并收到“NonConstantMemoryUsage”异常。

我没有按照错误消息的建议修改代表。我缺少什么?

[caliper] allocating java/lang/String with size 32 bytes 
[caliper] allocating char array with 16 elements with size 48 bytes 
[caliper] allocating char array with 16 elements with size 48 bytes 
[caliper] allocating java/lang/String with size 32 bytes  
[caliper] allocating char array with 1 elements with size 24 bytes 
[caliper] allocating java/lang/String with size 32 bytes 
[caliper] allocating char array with 16 elements with size 48 bytes 
[caliper] allocating java/lang/String with size 32 bytes 
[caliper] allocating char array with 1 elements with size 24 bytes 
[caliper] allocating java/lang/String with size 32 bytes 
[caliper] allocating char array with 16 elements with size 48 bytes 
[caliper] allocating java/lang/String with size 32 bytes 
[caliper] allocating char array with 34 elements with size 88 bytes 
[caliper] allocating char array with 1 elements with size 24 bytes 
[caliper] allocating java/lang/String with size 32 bytes 
[caliper] allocating char array with 16 elements with size 48 bytes 
[caliper] allocating java/lang/String with size 32 bytes 
[caliper] allocating char array with 1 elements with size 24 bytes 
[caliper] allocating java/lang/String with size 32 bytes 
[caliper] allocating char array with 16 elements with size 48 bytes 
[caliper] allocating java/lang/String with size 32 bytes 
[caliper] allocating char array with 70 elements with size 160 bytes 
[caliper] allocating char array with 1 elements with size 24 bytes 
[caliper] allocating java/lang/String with size 32 bytes 
[caliper] allocating java/lang/String with size 32 bytes 
[caliper] allocating char array with 142 elements with size 304 bytes 
[caliper] allocating char array with 74 elements with size 168 bytes 
[caliper] allocating java/lang/String with size 32 bytes

[caliper] allocating org/apache/commons/collections/map/AbstractReferenceMap$WeakRef with size 32 bytes 
[caliper] allocating org/apache/commons/collections/map/AbstractReferenceMap$ReferenceEntry with size 32 bytes 
[caliper] allocating java/lang/Object array with 0 elements with size 16 bytes 
[caliper] allocating java/lang/Object array with 1 elements with size 24 bytes 
[caliper] allocating java/lang/Object array with 1 elements with size 24 bytes 
[caliper] allocating java/lang/Object array with 1 elements with size 24 bytes 
[caliper] allocating java/lang/Object array with 1 elements with size 24 bytes 
[caliper] allocating java/lang/Object array with 1 elements with size 24 bytes 
[caliper] allocating java/lang/Object array with 1 elements with size 24 bytes 
[caliper] allocating java/lang/Object array with 1 elements with size 24 bytes 
[caliper] allocating org/joda/time/DateTime with size 24 bytes 
[caliper] allocating org/hibernate/util/IdentityMap$IdentityKey with size 16 bytes 
[caliper] allocating org/hibernate/event/LoadEvent with size 40 bytes 
[caliper] allocating org/hibernate/engine/EntityKey with size 48 bytes 
[caliper] allocating org/hibernate/event/LoadEvent with size 40 bytes 
[caliper] allocating org/hibernate/engine/EntityKey with size 48 bytes 
[caliper] allocating java/lang/Object array with 1 elements with size 24 bytes 
[caliper] allocating java/lang/Object array with 1 elements with size 24 bytes 
[caliper] allocating java/lang/Object array with 1 elements with size 24 bytes 
[caliper] allocating java/lang/Object array with 1 elements with size 24 bytes 
[caliper] ...more allocations... 
[caliper] [done measured section] 
[caliper] 482 instance(s) allocated per rep 
[caliper] 0 out of thread instance(s) allocated in 1 reps 
[caliper] [starting measured section] 
[caliper] see first run for list of allocations 
[caliper] [done measured section] 
[caliper] 2966 instance(s) allocated per rep 
[caliper] 0 out of thread instance(s) allocated in 2 reps 

错误:并非所有内循环重复都分配相同的次数!代表循环应使用恒定数量的分配。您是否在循环内使用代表的值?

现在,我评论了 AllocationMeasurer 中抛出 NonConstantMemoryUsage 的代码(不确定这是否是个好主意!),以便我可以进一步继续。我现在得到负字节分配。

0% Scenario{vm=java, trial=0, benchmark=GetCompleteUserInfoByEmail, length=1, trials=5, memory=-Xmx1024M} 5017892000.00 ns; σ=18238565.40 ns @ 3 trials, allocated -45356 instances for a total of -2873264B
50% Scenario{vm=java, trial=0, benchmark=GetUserByEmail, length=10, trials=5, memory=-Xmx1024M} 5044517000.00 ns; σ=25651666.81 ns @ 3 trials, allocated -45816 instances for a total of -2873264B

<代码> 长度      实例           B          线性运行时间
  1       -45356.000 -2873264.000 5.02 ===============================
  10       -45816.000 -2873264.000 5.04 ================================ 虚拟机

:java
试用:0
基准测试:GetCompleteUserInfoByEmail
试验:5
内存:-Xmx1024M

I was doing tests with MeasureMemory turned on and was getting "NonConstantMemoryUsage" exception.

I did not modify reps as suggested by error message. What am I missing?

[caliper] allocating java/lang/String with size 32 bytes 
[caliper] allocating char array with 16 elements with size 48 bytes 
[caliper] allocating char array with 16 elements with size 48 bytes 
[caliper] allocating java/lang/String with size 32 bytes  
[caliper] allocating char array with 1 elements with size 24 bytes 
[caliper] allocating java/lang/String with size 32 bytes 
[caliper] allocating char array with 16 elements with size 48 bytes 
[caliper] allocating java/lang/String with size 32 bytes 
[caliper] allocating char array with 1 elements with size 24 bytes 
[caliper] allocating java/lang/String with size 32 bytes 
[caliper] allocating char array with 16 elements with size 48 bytes 
[caliper] allocating java/lang/String with size 32 bytes 
[caliper] allocating char array with 34 elements with size 88 bytes 
[caliper] allocating char array with 1 elements with size 24 bytes 
[caliper] allocating java/lang/String with size 32 bytes 
[caliper] allocating char array with 16 elements with size 48 bytes 
[caliper] allocating java/lang/String with size 32 bytes 
[caliper] allocating char array with 1 elements with size 24 bytes 
[caliper] allocating java/lang/String with size 32 bytes 
[caliper] allocating char array with 16 elements with size 48 bytes 
[caliper] allocating java/lang/String with size 32 bytes 
[caliper] allocating char array with 70 elements with size 160 bytes 
[caliper] allocating char array with 1 elements with size 24 bytes 
[caliper] allocating java/lang/String with size 32 bytes 
[caliper] allocating java/lang/String with size 32 bytes 
[caliper] allocating char array with 142 elements with size 304 bytes 
[caliper] allocating char array with 74 elements with size 168 bytes 
[caliper] allocating java/lang/String with size 32 bytes

[caliper] allocating org/apache/commons/collections/map/AbstractReferenceMap$WeakRef with size 32 bytes 
[caliper] allocating org/apache/commons/collections/map/AbstractReferenceMap$ReferenceEntry with size 32 bytes 
[caliper] allocating java/lang/Object array with 0 elements with size 16 bytes 
[caliper] allocating java/lang/Object array with 1 elements with size 24 bytes 
[caliper] allocating java/lang/Object array with 1 elements with size 24 bytes 
[caliper] allocating java/lang/Object array with 1 elements with size 24 bytes 
[caliper] allocating java/lang/Object array with 1 elements with size 24 bytes 
[caliper] allocating java/lang/Object array with 1 elements with size 24 bytes 
[caliper] allocating java/lang/Object array with 1 elements with size 24 bytes 
[caliper] allocating java/lang/Object array with 1 elements with size 24 bytes 
[caliper] allocating org/joda/time/DateTime with size 24 bytes 
[caliper] allocating org/hibernate/util/IdentityMap$IdentityKey with size 16 bytes 
[caliper] allocating org/hibernate/event/LoadEvent with size 40 bytes 
[caliper] allocating org/hibernate/engine/EntityKey with size 48 bytes 
[caliper] allocating org/hibernate/event/LoadEvent with size 40 bytes 
[caliper] allocating org/hibernate/engine/EntityKey with size 48 bytes 
[caliper] allocating java/lang/Object array with 1 elements with size 24 bytes 
[caliper] allocating java/lang/Object array with 1 elements with size 24 bytes 
[caliper] allocating java/lang/Object array with 1 elements with size 24 bytes 
[caliper] allocating java/lang/Object array with 1 elements with size 24 bytes 
[caliper] ...more allocations... 
[caliper] [done measured section] 
[caliper] 482 instance(s) allocated per rep 
[caliper] 0 out of thread instance(s) allocated in 1 reps 
[caliper] [starting measured section] 
[caliper] see first run for list of allocations 
[caliper] [done measured section] 
[caliper] 2966 instance(s) allocated per rep 
[caliper] 0 out of thread instance(s) allocated in 2 reps 

Error: Not all reps of the inner loop allocate the same number of times! The reps loop should use a constant number of allocations. Are you using the value of reps inside the loop?

For now I commented the code in AllocationMeasurer which was throwing NonConstantMemoryUsage (Not sure if it's good idea!) so that I could continue further. I am now getting negative bytes allocation.

0% Scenario{vm=java, trial=0, benchmark=GetCompleteUserInfoByEmail, length=1, trials=5, memory=-Xmx1024M} 5017892000.00 ns; σ=18238565.40 ns @ 3 trials, allocated -45356 instances for a total of -2873264B
50% Scenario{vm=java, trial=0, benchmark=GetUserByEmail, length=10, trials=5, memory=-Xmx1024M} 5044517000.00 ns; σ=25651666.81 ns @ 3 trials, allocated -45816 instances for a total of -2873264B


length     instances        B       s        linear runtime
  1        -45356.000 -2873264.000 5.02 =============================
  10       -45816.000 -2873264.000 5.04 ==============================

vm: java
trial: 0
benchmark: GetCompleteUserInfoByEmail
trials: 5
memory: -Xmx1024M

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文