Skip to content

Commit

Permalink
performance analysis (#296)
Browse files Browse the repository at this point in the history
* add agent performance analysis

* Application performance analysis, supporting the following features.
- ThreadDump
- DeadLockDetect
- JavaFlameGraph
- Metrics
- JTop
- VMFlags
- HeapDump
- JMapHisto
- JHat

* No more init performance analysis code inside the  femas agent.

* Resolving conflicts with develop branches
  • Loading branch information
zilongTong authored Apr 26, 2023
1 parent 99a2e2b commit ace728b
Show file tree
Hide file tree
Showing 79 changed files with 7,217 additions and 392 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,25 +107,25 @@ private static List<ServiceInstance> chooseColorfulInstances(List<ServiceInstanc

LOGGER.debug("[FEMAS LANE] Choose Colorful instances. Femas lane take effect, color service list = {}",
serverList);


return serverList;
}

/**
* 将有色节点选择出来
* 将无色节点选择出来
*/
private static List<ServiceInstance> chooseColorlessInstances(Service service,
List<ServiceInstance> serviceInstances) {
List<ServiceInstance> instances = new ArrayList<>();
String namespaceId = service.getNamespace();

/**
* 该命名空间下没有配置泳道信息
*/
if (namespaceId == null || !NAMESPACE_LANE_INFO_MAP.containsKey(namespaceId) || NAMESPACE_LANE_INFO_MAP
.get(namespaceId).isEmpty()) {
return serviceInstances;
}

Set<ServiceInstance> colorInstances = new HashSet<>();
for (ServiceInstance instance : serviceInstances) {
String groupId = instance.getMetadata(FemasConstant.FEMAS_META_APPLICATION_VERSION_KEY);
Expand All @@ -138,16 +138,13 @@ private static List<ServiceInstance> chooseColorlessInstances(Service service,

instances.add(instance);
}

if (!CollectionUtil.isEmpty(colorInstances)) {
LOGGER.debug("[FEMAS LANE] Choose Colorless instances. lane take effect, filter color instance list = {}",
colorInstances);
}

if (CollectionUtil.isEmpty(instances)) {
return serviceInstances;
}

return instances;

}
Expand Down Expand Up @@ -264,15 +261,13 @@ private static synchronized void resortLaneRule() {

public static synchronized void addLaneRule(LaneRule laneRule) {
ALL_LANE_RULES.add(laneRule);

refreshEffectiveLaneRule();
}

public static synchronized void removeLaneRule(LaneRule laneRule) {
ALL_LANE_RULES.remove(laneRule);
EFFECTIVE_LANE_RULES_SET.remove(laneRule);
EFFECTIVE_LANE_RULES.remove(laneRule);

LOGGER.info("EFFECTIVE LANE Rule changed. EFFECTIVE_LANE_RULES : " + EFFECTIVE_LANE_RULES);
}

Expand Down Expand Up @@ -376,6 +371,9 @@ private String getLaneIdByPercentage(Map<String, Integer> laneMap) {
return weightMap.get(tailMap.firstKey());
}




@Override
public String getName() {
return "femasLane";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,4 +402,4 @@ private int findEndpointPort(EndpointSubset s, String serviceId, String primaryP
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,22 @@ public class OpenApiFactory {
private final NacosRegistryOpenApi nacosRegistryOpenApi;
private final EurekaRegistryOpenApi eurekaRegistryOpenApi;
private final ConsulRegistryOpenApi consulRegistryOpenApi;
private final KubernetesFabricRegistryOpenApi k8sRegistryOpenApi;
// private final KubernetesFabricRegistryOpenApi k8sRegistryOpenApi;
private final PolarisRegistryOpenApi polarisRegistryOpenApi;

private final Map<String, RegistryOpenApiInterface> registryOpenApiInterfaceMapCache = new ConcurrentHashMap<>();

public OpenApiFactory(NacosRegistryOpenApi nacosRegistryOpenApi, EurekaRegistryOpenApi eurekaRegistryOpenApi, ConsulRegistryOpenApi consulRegistryOpenApi, KubernetesFabricRegistryOpenApi k8sRegistryOpenApi, PolarisRegistryOpenApi polarisRegistryOpenApi) {
public OpenApiFactory(NacosRegistryOpenApi nacosRegistryOpenApi, EurekaRegistryOpenApi eurekaRegistryOpenApi, ConsulRegistryOpenApi consulRegistryOpenApi, PolarisRegistryOpenApi polarisRegistryOpenApi) {
this.nacosRegistryOpenApi = nacosRegistryOpenApi;
this.eurekaRegistryOpenApi = eurekaRegistryOpenApi;
this.consulRegistryOpenApi = consulRegistryOpenApi;
this.k8sRegistryOpenApi = k8sRegistryOpenApi;
// this.k8sRegistryOpenApi = k8sRegistryOpenApi;
this.polarisRegistryOpenApi = polarisRegistryOpenApi;
registryOpenApiInterfaceMapCache.put(RegistryEnum.CONSUL.getAlias(), consulRegistryOpenApi);
registryOpenApiInterfaceMapCache.put(RegistryEnum.NACOS.getAlias(), nacosRegistryOpenApi);
registryOpenApiInterfaceMapCache.put(RegistryEnum.EUREKA.getAlias(), eurekaRegistryOpenApi);
registryOpenApiInterfaceMapCache.put(RegistryEnum.KUBERNETES.getAlias(), k8sRegistryOpenApi);
// registryOpenApiInterfaceMapCache.put(RegistryEnum.KUBERNETES.getAlias(), k8sRegistryOpenApi);
registryOpenApiInterfaceMapCache.put(RegistryEnum.POLARIS.getAlias(), polarisRegistryOpenApi);

}

public RegistryOpenApiInterface select(String type) {
Expand Down
12 changes: 12 additions & 0 deletions femas-agent/femas-agent-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@
<artifactId>femas-agent-tools</artifactId>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* Copyright 2010-2021 the original author or authors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.tencent.tsf.femas.agent.classloader;


import com.tencent.tsf.femas.agent.tools.Logger;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLClassLoader;

public class JvmMonitorClassloader extends URLClassLoader {
private static final Logger LOGGER = Logger.getLogger(JvmMonitorClassloader.class);
// only enable at develop phase.
private static final Boolean DUMP_LOADED_CLASSES = false;

public JvmMonitorClassloader(URL[] urls) {
super(urls);
}

@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
byte[] b = loadClassData(name);
return defineClass(name, b, 0, b.length);
}

private byte[] loadClassData(String className) {
if (DUMP_LOADED_CLASSES) {
LOGGER.debug("load class: " + className.replace(".", "/") + ".class");
}
// read class
InputStream is = getClass().getClassLoader().getResourceAsStream(
className.replace(".", "/") + ".class");
ByteArrayOutputStream byteSt = new ByteArrayOutputStream();
// write into byte
int len = 0;
try {
while ((len = is.read()) != -1) {
byteSt.write(len);
}
} catch (IOException e) {
e.printStackTrace();
}
// convert into byte array
return byteSt.toByteArray();
}
}
Loading

0 comments on commit ace728b

Please sign in to comment.