Poison


  • 首页

  • 归档

  • 标签

  • 搜索
close
Poison

jvm-profiler

发表于 2021-06-25

最近在做 Java Agent 的相关开发,在查询相关开源 Java Agent 实现时想起了 Uber 的 jvm-profiler,之前在开发 Spark 相关应用时了解过该 Agent,最近处理 Java Agent 的类隔离又想起了它,于是看了看相关实现,其中 premain 方法的入口如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
* Copyright (c) 2018 Uber Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.uber.profiling;

import java.lang.instrument.Instrumentation;

public final class Agent {

private static AgentImpl agentImpl = new AgentImpl();

private Agent() {
}

public static void agentmain(final String args, final Instrumentation instrumentation) {
premain(args, instrumentation);
}

public static void premain(final String args, final Instrumentation instrumentation) {
System.out.println("Java Agent " + AgentImpl.VERSION + " premain args: " + args);

Arguments arguments = Arguments.parseArgs(args);
arguments.runConfigProvider();
agentImpl.run(arguments, instrumentation, null);
}
}

其中 agentImpl.run 方法的实现见:AgentImpl.java,在入口处没有看见有创建独立的类加载器的相关逻辑,而在 pom.xml 中看到使用 maven-shade-plugin 对类进行了重定位,并未实现物理隔离。

阅读全文 »
Poison

ClassLoader.registerAsParallelCapable()

发表于 2021-06-22

最近在做 Java Agent 的相关开发,参考部分开源代码实现的自定义类加载器实现时,部分类加载器实现含有以下静态块:

1
2
3
static {
ClassLoader.registerAsParallelCapable();
}
阅读全文 »
Poison

EMR-OSS #369

发表于 2021-06-14

在我之前的工程中,使用 EMR-OSS 将 阿里云对象存储 OSS 与 Spark 集群进行了整合,采用 OSS 作为存储实现,在一次性能问题排查过程中,发现 EMR-OSS 连接器的代码中有对 System.gc() 的显式调用,该调用导致频繁 FullGC,在修复前我先使用 JVM 参数 -XX:+DisableExplicitGC 规避了频繁 FullGC 的问题,后提交了 PR 对该问题进行修复。

注:设置 -XX:+DisableExplicitGC 可能影响直接内存回收,使用该选项须谨慎。

References

Remove explicit calls to System.gc() #369
GCeasy
Impact of setting -XX:+DisableExplicitGC when NIO direct buffers are used - Stack Overflow

Poison

Spring Data Redis #1721

发表于 2021-06-14

该问题我在 2020 年 02 月 04 日排查线上 Redis 性能抖动时发现,当时 spring-data-redis 的 @Cacheable 对 allEntries = true 的实现机制仅有 keys 命令一种,当时我仅将项目中 allEntries = true 调整为指定 key 的方式绕开了对 keys 命令的调用,最近看到 spring-data-redis 已经新增了对 SCAN 命令的支持。

@Cacheable allEntries = true

如果查看 Redis 官网中对 KEYS pattern 命令的介绍就能知道,该命令时间复杂度为 O(N),并且在警告中提到,应谨慎在生产环境中使用,若在大型数据库上执行该命令,可能导致糟糕的性能,此命令应用于调试或其他指定的操作,不要在常规的应用程序代码中使用 KEYS 命令,如果你在寻找一种在整个键空间中查询键的子集的方式,请考虑使用 SCAN 或 sets 命令。

在 2020 年 05 月 21 日有人在 GitHub 提出了关于该问题的 issue: DefaultRedisCacheWriter.clean() uses blocking KEYS command [DATAREDIS-1151] #1721

基于 SCAN 命令的实现在 2021 年 04 月 21 日被提交,参考:Add support for configurable batch strategies using RedisCache.

Poison

ThreadLocal

发表于 2021-05-27

在Thread 类的源码中,可以看到以下声明:

1
2
3
4
5
6
7
8
public
class Thread implements Runnable {

/* ThreadLocal values pertaining to this thread. This map is maintained
* by the ThreadLocal class. */
ThreadLocal.ThreadLocalMap threadLocals = null;

}

可以看出,Thread 的实例持有了对 ThreadLocal.ThreadLocalMap 实例 threadLocals 的引用。

阅读全文 »
1…222324…27

131 日志
119 标签
GitHub LeetCode
© 2025 Poison 蜀ICP备16000644号
由 Hexo 强力驱动
主题 - NexT.Mist