mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-17 16:56:15 +10:00
Merge remote-tracking branch 'upstream/master'
# Please enter a commit message to explain why this merge is necessary, # especially if it merges an updated upstream into a topic branch. # # Lines starting with '#' will be ignored, and an empty message aborts # the commit.
This commit is contained in:
@@ -78,7 +78,7 @@ public final class BytecodeUtils {
|
||||
if (closeable != null) {
|
||||
try {
|
||||
closeable.close();
|
||||
} catch (IOException e) {
|
||||
} catch (IOException ignore) {
|
||||
// skip
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -280,8 +280,9 @@ public class ZookeeperLatestJobWorker implements Runnable {
|
||||
while (latestJobRepository.size() == 0 && !isOverWaitTime(waitTime, startTimeMillis) && workerState.isStarted()) {
|
||||
try {
|
||||
lock.wait(waitUnitTime);
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
} catch (InterruptedException ignore) {
|
||||
// Thread.currentThread().interrupt();
|
||||
// TODO check Interrupted state
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ public final class ClassLoaderUtils {
|
||||
if (contextClassLoader != null) {
|
||||
return contextClassLoader;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
} catch (Throwable ignore) {
|
||||
// skip
|
||||
}
|
||||
// 파라미터로 ClassLoader를 전달 받으면 security exception 의 발생타이밍이 다르다.
|
||||
|
||||
@@ -25,7 +25,7 @@ public final class ClassUtils {
|
||||
}
|
||||
try {
|
||||
return (classLoaderToUse.loadClass(name) != CLASS_NOT_LOADED);
|
||||
} catch (ClassNotFoundException e) {
|
||||
} catch (ClassNotFoundException ignore) {
|
||||
// Swallow
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -41,7 +41,8 @@ public final class NetUtils {
|
||||
URI uri = new URI("pinpoint://" + address);
|
||||
|
||||
return new InetSocketAddress(uri.getHost(), uri.getPort());
|
||||
} catch (URISyntaxException e) {
|
||||
} catch (URISyntaxException ignore) {
|
||||
// skip
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -54,7 +55,8 @@ public final class NetUtils {
|
||||
if (validationIpV4FormatAddress(localIp)) {
|
||||
return localIp;
|
||||
}
|
||||
} catch (UnknownHostException e) {
|
||||
} catch (UnknownHostException ignore) {
|
||||
// skip
|
||||
}
|
||||
return LOOPBACK_ADDRESS_V4;
|
||||
}
|
||||
@@ -69,7 +71,8 @@ public final class NetUtils {
|
||||
Enumeration<NetworkInterface> interfaces = null;
|
||||
try {
|
||||
interfaces = NetworkInterface.getNetworkInterfaces();
|
||||
} catch (SocketException e) {
|
||||
} catch (SocketException ignore) {
|
||||
// skip
|
||||
}
|
||||
|
||||
if (interfaces == null) {
|
||||
@@ -104,7 +107,8 @@ public final class NetUtils {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
} catch (Exception ignore) {
|
||||
// skip
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -130,7 +134,8 @@ public final class NetUtils {
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
} catch (Exception ignore) {
|
||||
//skip
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -149,7 +154,8 @@ public final class NetUtils {
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (NumberFormatException e) {
|
||||
} catch (NumberFormatException ignore) {
|
||||
// skip
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -191,9 +191,9 @@ function func_start_pinpoint_testapp
|
||||
echo "---$TESTAPP_IDENTIFIER initialization started. pid=$pid.---"
|
||||
|
||||
end_count=0
|
||||
process_status=`curl $check_url 2>/dev/null`
|
||||
process_status=`curl $check_url 2>/dev/null | grep 'getCurrentTimestamp'`
|
||||
|
||||
until [[ $process_status =~ ^-?[0-9]+$ ]];
|
||||
while [ -z $process_status];
|
||||
do
|
||||
wait_time=`expr $end_count \* $UNIT_TIME`
|
||||
echo "starting $TESTAPP_IDENTIFIER. $wait_time sec/$CLOSE_WAIT_TIME sec(close wait limit)."
|
||||
@@ -204,7 +204,7 @@ function func_start_pinpoint_testapp
|
||||
|
||||
sleep $UNIT_TIME
|
||||
end_count=`expr $end_count + 1`
|
||||
process_status=`curl $check_url 2>/dev/null`
|
||||
process_status=`curl $check_url 2>/dev/null | grep 'getCurrentTimestamp'`
|
||||
|
||||
done
|
||||
|
||||
|
||||
+99
-12
@@ -1,5 +1,8 @@
|
||||
package com.navercorp.pinpoint.testapp.controller;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
@@ -11,6 +14,7 @@ import javax.annotation.PostConstruct;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
@@ -20,46 +24,129 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl
|
||||
/**
|
||||
* @author koo.taejin
|
||||
*/
|
||||
import com.navercorp.pinpoint.testapp.util.Description;
|
||||
|
||||
@Controller(value = "apisController")
|
||||
public class ApisController {
|
||||
|
||||
private final RequestMappingHandlerMapping handlerMapping;
|
||||
|
||||
private final Map<String, SortedSet<String>> apiMappings = new TreeMap<String, SortedSet<String>>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
|
||||
private final Map<String, SortedSet<RequestMappedUri>> apiMappings = new TreeMap<String, SortedSet<RequestMappedUri>>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
@Autowired
|
||||
public ApisController(RequestMappingHandlerMapping handlerMapping) {
|
||||
this.handlerMapping = handlerMapping;
|
||||
}
|
||||
|
||||
|
||||
@PostConstruct
|
||||
private void initApiMappings() {
|
||||
Map<RequestMappingInfo, HandlerMethod> requestMappedHandlers = this.handlerMapping.getHandlerMethods();
|
||||
for (Map.Entry<RequestMappingInfo, HandlerMethod> requestMappedHandlerEntry : requestMappedHandlers.entrySet()) {
|
||||
RequestMappingInfo requestMappingInfo = requestMappedHandlerEntry.getKey();
|
||||
HandlerMethod handlerMethod = requestMappedHandlerEntry.getValue();
|
||||
|
||||
|
||||
Class<?> handlerMethodBeanClazz = handlerMethod.getBeanType();
|
||||
if (handlerMethodBeanClazz == this.getClass()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
String controllerName = handlerMethodBeanClazz.getSimpleName();
|
||||
Set<String> mappedRequests = requestMappingInfo.getPatternsCondition().getPatterns();
|
||||
|
||||
SortedSet<String> alreadyMappedRequests = this.apiMappings.get(controllerName);
|
||||
|
||||
SortedSet<RequestMappedUri> alreadyMappedRequests = this.apiMappings.get(controllerName);
|
||||
if (alreadyMappedRequests == null) {
|
||||
alreadyMappedRequests = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
|
||||
alreadyMappedRequests = new TreeSet<RequestMappedUri>(RequestMappedUri.MAPPED_URI_ORDER);
|
||||
this.apiMappings.put(controllerName, alreadyMappedRequests);
|
||||
}
|
||||
alreadyMappedRequests.addAll(mappedRequests);
|
||||
alreadyMappedRequests.addAll(createRequestMappedApis(handlerMethod, mappedRequests));
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = {"/index.html", "/apis"}, method = RequestMethod.GET)
|
||||
private Set<RequestMappedUri> createRequestMappedApis(HandlerMethod handlerMethod, Set<String> mappedUris) {
|
||||
if (CollectionUtils.isEmpty(mappedUris)) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
Set<RequestMappedUri> requestMappedUris = new HashSet<RequestMappedUri>(mappedUris.size());
|
||||
Description description = handlerMethod.getMethodAnnotation(Description.class);
|
||||
for (String mappedUri : mappedUris) {
|
||||
requestMappedUris.add(new RequestMappedUri(mappedUri, description));
|
||||
}
|
||||
return requestMappedUris;
|
||||
}
|
||||
|
||||
@RequestMapping(value = { "/index.html", "/apis" }, method = RequestMethod.GET)
|
||||
public String apis(Model model) {
|
||||
model.addAttribute("apiMappings", this.apiMappings);
|
||||
return "apis";
|
||||
}
|
||||
|
||||
|
||||
public static class RequestMappedUri {
|
||||
|
||||
private final String mappedUri;
|
||||
private final String description;
|
||||
|
||||
private RequestMappedUri(String mappedUri, Description description) {
|
||||
if (mappedUri == null) {
|
||||
throw new IllegalArgumentException("mappedUri must not be null");
|
||||
}
|
||||
this.mappedUri = mappedUri;
|
||||
this.description = description == null ? "" : description.value();
|
||||
}
|
||||
|
||||
public String getMappedUri() {
|
||||
return this.mappedUri;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
private static final Comparator<RequestMappedUri> MAPPED_URI_ORDER = new Comparator<RequestMappedUri>() {
|
||||
@Override
|
||||
public int compare(RequestMappedUri arg0, RequestMappedUri arg1) {
|
||||
if (arg0 == null && arg1 == null) return 0;
|
||||
if (arg1 == null) return -1;
|
||||
if (arg0 == null) return 1;
|
||||
return String.CASE_INSENSITIVE_ORDER.compare(arg0.mappedUri, arg1.mappedUri);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((description == null) ? 0 : description.hashCode());
|
||||
result = prime * result + ((mappedUri == null) ? 0 : mappedUri.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
RequestMappedUri other = (RequestMappedUri) obj;
|
||||
if (description == null) {
|
||||
if (other.description != null)
|
||||
return false;
|
||||
} else if (!description.equals(other.description))
|
||||
return false;
|
||||
if (mappedUri == null) {
|
||||
if (other.mappedUri != null)
|
||||
return false;
|
||||
} else if (!mappedUri.equals(other.mappedUri))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RequestMappedUri [mappedUri=" + mappedUri + ", description=" + description + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
package com.navercorp.pinpoint.testapp.controller;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.http.client.utils.URIBuilder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.navercorp.pinpoint.testapp.service.remote.RemoteService;
|
||||
import com.navercorp.pinpoint.testapp.util.Description;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/callSelf")
|
||||
public class CallSelfController {
|
||||
|
||||
private static final String GET_CURRENT_TIMESTAMP_PATH = "/getCurrentTimestamp";
|
||||
private static final String GET_GEO_CODE_PATH = "/httpclient4/getGeoCode";
|
||||
private static final String GET_TWITTER_URL_COUNT_PATH = "/httpclient4/getTwitterUrlCount";
|
||||
|
||||
private static final String DEFAULT_LOCAL_IP = "127.0.0.1";
|
||||
private static final String LOCAL_IP = getLocalHostIp();
|
||||
|
||||
private static String getLocalHostIp() {
|
||||
try {
|
||||
final InetAddress localHost = InetAddress.getLocalHost();
|
||||
return localHost.getHostAddress();
|
||||
} catch (UnknownHostException e) {
|
||||
}
|
||||
return DEFAULT_LOCAL_IP;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
@Qualifier("httpRemoteService")
|
||||
RemoteService remoteService;
|
||||
|
||||
@RequestMapping("/getCurrentTimestamp")
|
||||
@ResponseBody
|
||||
@Description("Calls self for " + GET_CURRENT_TIMESTAMP_PATH + " over HTTP.")
|
||||
public Map<String, Object> getCurrentTimeStamp(HttpServletRequest request) throws Exception {
|
||||
String url = createTargetUrl(request, GET_CURRENT_TIMESTAMP_PATH);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> response = remoteService.get(url, Map.class);
|
||||
return response;
|
||||
}
|
||||
|
||||
@RequestMapping("/httpclient4/getGeoCode")
|
||||
@ResponseBody
|
||||
@Description("Calls self for " + GET_GEO_CODE_PATH + " over HTTP.")
|
||||
public Map<String, Object> httpClient4GetGeoCode(HttpServletRequest request) throws Exception {
|
||||
String url = createTargetUrl(request, GET_GEO_CODE_PATH);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> response = remoteService.get(url, Map.class);
|
||||
return response;
|
||||
}
|
||||
|
||||
@RequestMapping("/httpclient4/getTwitterUrlCount")
|
||||
@ResponseBody
|
||||
@Description("Calls self for " + GET_TWITTER_URL_COUNT_PATH + " over HTTP.")
|
||||
public Map<String, Object> httpClient4GetTwitterUrlCount(HttpServletRequest request) throws Exception {
|
||||
String url = createTargetUrl(request, GET_TWITTER_URL_COUNT_PATH);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> response = remoteService.get(url, Map.class);
|
||||
return response;
|
||||
}
|
||||
|
||||
private static final String createTargetUrl(final HttpServletRequest request, final String path) throws URISyntaxException {
|
||||
return new URIBuilder()
|
||||
.setScheme("http")
|
||||
.setHost(LOCAL_IP)
|
||||
.setPort(request.getLocalPort())
|
||||
.setPath(path + ".pinpoint")
|
||||
.build()
|
||||
.toString();
|
||||
}
|
||||
|
||||
}
|
||||
+11
-6
@@ -2,6 +2,8 @@ package com.navercorp.pinpoint.testapp.controller;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -21,40 +23,43 @@ public class HttpClient4Controller {
|
||||
|
||||
private static final String GOOGLE_GEOCODE_URL = "http://maps.googleapis.com/maps/api/geocode/json";
|
||||
private static final String TWITTER_URL_COUNT_URL = "http://urls.api.twitter.com/1/urls/count.json";
|
||||
|
||||
|
||||
private static final String DEFAULT_GET_GEOCODE_ADDRESS = "Gyeonggi-do, Seongnam-si, Bundang-gu, Jeongja-dong, 178-1";
|
||||
private static final String DEFAULT_GET_TWITTER_URL_COUNT_URL = "http://www.naver.com";
|
||||
|
||||
RemoteService remoteOperations = new HttpRemoteService();
|
||||
@Autowired
|
||||
@Qualifier("httpRemoteService")
|
||||
RemoteService remoteService;
|
||||
|
||||
@RequestMapping("/getGeoCode")
|
||||
@Description("")
|
||||
@ResponseBody
|
||||
@Description("HTTP GET to " + GOOGLE_GEOCODE_URL)
|
||||
public Map<String, Object> getGeoCode(@RequestParam(defaultValue = DEFAULT_GET_GEOCODE_ADDRESS, required = false) String address) throws Exception {
|
||||
LinkedMultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
|
||||
params.add("address", address);
|
||||
params.add("sensor", "false");
|
||||
|
||||
return remoteOperations.get(GOOGLE_GEOCODE_URL, params, Map.class);
|
||||
return remoteService.get(GOOGLE_GEOCODE_URL, params, Map.class);
|
||||
}
|
||||
|
||||
@RequestMapping("/getTwitterUrlCount")
|
||||
@ResponseBody
|
||||
@Description("HTTP GET to " + TWITTER_URL_COUNT_URL)
|
||||
public Map<String, Object> getTwitterUrlCount(@RequestParam(defaultValue = DEFAULT_GET_TWITTER_URL_COUNT_URL, required = false) String url) throws Exception {
|
||||
LinkedMultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
|
||||
params.add("url", url);
|
||||
|
||||
return remoteOperations.get(TWITTER_URL_COUNT_URL, params, Map.class);
|
||||
return remoteService.get(TWITTER_URL_COUNT_URL, params, Map.class);
|
||||
}
|
||||
|
||||
@RequestMapping("/getTwitterUrlCountByPost")
|
||||
@ResponseBody
|
||||
@Description("HTTP POST to " + TWITTER_URL_COUNT_URL)
|
||||
public Map<String, Object> getTwitterUrlCountByPost(@RequestParam(defaultValue = DEFAULT_GET_TWITTER_URL_COUNT_URL, required = false) String url) throws Exception {
|
||||
LinkedMultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
|
||||
params.add("url", url);
|
||||
|
||||
return remoteOperations.post(TWITTER_URL_COUNT_URL, params, Map.class);
|
||||
return remoteService.post(TWITTER_URL_COUNT_URL, params, Map.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+6
-96
@@ -1,17 +1,14 @@
|
||||
package com.navercorp.pinpoint.testapp.controller;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.navercorp.pinpoint.testapp.util.Description;
|
||||
|
||||
/**
|
||||
* @author koo.taejin
|
||||
*/
|
||||
@@ -20,6 +17,7 @@ public class SimpleController {
|
||||
|
||||
@RequestMapping("/getCurrentTimestamp")
|
||||
@ResponseBody
|
||||
@Description("Returns the server's current timestamp.")
|
||||
public Map<String, Object> getCurrentTimestamp() {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("getCurrentTimestamp", System.currentTimeMillis());
|
||||
@@ -27,99 +25,9 @@ public class SimpleController {
|
||||
return map;
|
||||
}
|
||||
|
||||
@RequestMapping("/consumeCpu")
|
||||
@ResponseBody
|
||||
public Map<String, Object> consumeCpu() throws InterruptedException {
|
||||
int cpuCount = Runtime.getRuntime().availableProcessors();
|
||||
int threadSize = Math.max(1, cpuCount - 1);
|
||||
|
||||
long limitTime = 10000;
|
||||
CountDownLatch latch = new CountDownLatch(threadSize);
|
||||
|
||||
for (int i = 0; i < threadSize; i++) {
|
||||
Thread thread = new Thread(new ConsumeCpu(latch, limitTime));
|
||||
thread.setDaemon(true);
|
||||
|
||||
thread.start();
|
||||
}
|
||||
|
||||
latch.await();
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("message", "ok");
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
class ConsumeCpu implements Runnable {
|
||||
|
||||
private final CountDownLatch latch;
|
||||
private final long limitTime;
|
||||
|
||||
public ConsumeCpu(CountDownLatch latch, long limitTime) {
|
||||
this.latch = latch;
|
||||
this.limitTime = limitTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
try {
|
||||
BigDecimal decimal = new BigDecimal(0);
|
||||
for (int num = 1; num < Integer.MAX_VALUE; num++) {
|
||||
long currentTimeMillis = System.currentTimeMillis();
|
||||
|
||||
if (currentTimeMillis - startTime > limitTime) {
|
||||
break;
|
||||
}
|
||||
|
||||
decimal.add(new BigDecimal(num));
|
||||
}
|
||||
} finally {
|
||||
latch.countDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping("/consumeMemory")
|
||||
@ResponseBody
|
||||
public Map<String, Object> consumeMemory() throws InterruptedException {
|
||||
consumeMemory(1024 * 16, 20);
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("message", "ok");
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("/consumeMemoryLarge")
|
||||
@ResponseBody
|
||||
public Map<String, Object> consumeMemoryLarge() throws InterruptedException {
|
||||
consumeMemory(1024 * 16, 100);
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("message", "ok");
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
private void consumeMemory(int byteArraySize, int createMaxHeapCount) {
|
||||
long heapSize = Runtime.getRuntime().maxMemory();
|
||||
|
||||
int count = (int) Math.max(1, (heapSize/byteArraySize) * createMaxHeapCount);
|
||||
|
||||
List<WeakReference<byte[]>> weakReferece = new ArrayList<WeakReference<byte[]>>();
|
||||
for (int i = 0; i < count; i++) {
|
||||
weakReferece.add(new WeakReference<byte[]>(new byte[byteArraySize]));
|
||||
}
|
||||
|
||||
System.gc();
|
||||
}
|
||||
|
||||
@RequestMapping("/sleep3")
|
||||
@ResponseBody
|
||||
@Description("Call that takes 3 seconds to complete.")
|
||||
public Map<String, Object> sleep3() throws InterruptedException {
|
||||
Thread.sleep(3000);
|
||||
|
||||
@@ -131,6 +39,7 @@ public class SimpleController {
|
||||
|
||||
@RequestMapping("/sleep5")
|
||||
@ResponseBody
|
||||
@Description("Call that takes 5 seconds to complete")
|
||||
public Map<String, Object> sleep5() throws InterruptedException {
|
||||
Thread.sleep(5000);
|
||||
|
||||
@@ -142,6 +51,7 @@ public class SimpleController {
|
||||
|
||||
@RequestMapping("/sleep7")
|
||||
@ResponseBody
|
||||
@Description("Call that takes 7 seconds to complete")
|
||||
public Map<String, Object> sleep7() throws InterruptedException {
|
||||
Thread.sleep(7000);
|
||||
|
||||
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
package com.navercorp.pinpoint.testapp.controller;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.navercorp.pinpoint.testapp.util.Description;
|
||||
|
||||
@Controller
|
||||
public class StressController {
|
||||
|
||||
@RequestMapping("/consumeCpu")
|
||||
@ResponseBody
|
||||
@Description("Call that consumes a lot of cpu time.")
|
||||
public Map<String, Object> consumeCpu() throws InterruptedException {
|
||||
int cpuCount = Runtime.getRuntime().availableProcessors();
|
||||
int threadSize = Math.max(1, cpuCount - 1);
|
||||
|
||||
long limitTime = 10000;
|
||||
CountDownLatch latch = new CountDownLatch(threadSize);
|
||||
|
||||
for (int i = 0; i < threadSize; i++) {
|
||||
Thread thread = new Thread(new ConsumeCpu(latch, limitTime));
|
||||
thread.setDaemon(true);
|
||||
|
||||
thread.start();
|
||||
}
|
||||
|
||||
latch.await();
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("message", "ok");
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
class ConsumeCpu implements Runnable {
|
||||
|
||||
private final CountDownLatch latch;
|
||||
private final long limitTime;
|
||||
|
||||
public ConsumeCpu(CountDownLatch latch, long limitTime) {
|
||||
this.latch = latch;
|
||||
this.limitTime = limitTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
try {
|
||||
BigDecimal decimal = new BigDecimal(0);
|
||||
for (int num = 1; num < Integer.MAX_VALUE; num++) {
|
||||
long currentTimeMillis = System.currentTimeMillis();
|
||||
|
||||
if (currentTimeMillis - startTime > limitTime) {
|
||||
break;
|
||||
}
|
||||
|
||||
decimal.add(new BigDecimal(num));
|
||||
}
|
||||
} finally {
|
||||
latch.countDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping("/consumeMemory")
|
||||
@ResponseBody
|
||||
@Description("Call that consumes some memory that may trigger a few garbage collections.")
|
||||
public Map<String, Object> consumeMemory() throws InterruptedException {
|
||||
consumeMemory(1024 * 16, 20);
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("message", "ok");
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
@RequestMapping("/consumeMemoryLarge")
|
||||
@ResponseBody
|
||||
@Description("Call that consumes a large amount of memory that will most likely trigger multiple garbage collections.")
|
||||
public Map<String, Object> consumeMemoryLarge() throws InterruptedException {
|
||||
consumeMemory(1024 * 16, 100);
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("message", "ok");
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
private void consumeMemory(int byteArraySize, int createMaxHeapCount) {
|
||||
long heapSize = Runtime.getRuntime().maxMemory();
|
||||
|
||||
int count = (int) Math.max(1, (heapSize/byteArraySize) * createMaxHeapCount);
|
||||
|
||||
List<WeakReference<byte[]>> weakReferece = new ArrayList<WeakReference<byte[]>>();
|
||||
for (int i = 0; i < count; i++) {
|
||||
weakReferece.add(new WeakReference<byte[]>(new byte[byteArraySize]));
|
||||
}
|
||||
|
||||
System.gc();
|
||||
}
|
||||
}
|
||||
+2
@@ -17,6 +17,7 @@ import org.apache.http.client.utils.URIBuilder;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
@@ -25,6 +26,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
/**
|
||||
* @author koo.taejin
|
||||
*/
|
||||
@Component
|
||||
public class HttpRemoteService implements RemoteService {
|
||||
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@@ -12,12 +12,6 @@
|
||||
<context:component-scan base-package="com.navercorp.pinpoint.testapp.controller" />
|
||||
<context:component-scan base-package="com.navercorp.pinpoint.testapp.service" />
|
||||
|
||||
<bean id="httpComponentsClientHttpRequestFactory" class="org.springframework.http.client.HttpComponentsClientHttpRequestFactory" />
|
||||
|
||||
<bean id="closeableHttpClientRestTemplate" class="org.springframework.web.client.RestTemplate">
|
||||
<constructor-arg ref="httpComponentsClientHttpRequestFactory" />
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
|
||||
<property name="mappings">
|
||||
<props>
|
||||
|
||||
@@ -14,11 +14,12 @@
|
||||
<div class="thumbnail">
|
||||
<div class="caption">
|
||||
<h5>${apiMapping.key}</h5>
|
||||
<ul class="list-unstyled">
|
||||
<dl>
|
||||
<c:forEach items="${apiMapping.value}" var="api">
|
||||
<li><a href="${api}.pinpoint">${api}</a></li>
|
||||
<dt><a href="${api.mappedUri}.pinpoint">${api.mappedUri}</a></dt>
|
||||
<dd><small>${api.description}</small></dd>
|
||||
</c:forEach>
|
||||
</ul>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+2
-1
@@ -94,7 +94,8 @@ public class HttpUriRequestExecuteInterceptor extends AbstractHttpRequestExecute
|
||||
if (len > 0) {
|
||||
try {
|
||||
port = Integer.parseInt(host.substring(pos, pos + len));
|
||||
} catch (NumberFormatException ex) {
|
||||
} catch (NumberFormatException ignore) {
|
||||
// skip
|
||||
}
|
||||
}
|
||||
host = host.substring(0, colon);
|
||||
|
||||
@@ -23,7 +23,8 @@ public class Types {
|
||||
try {
|
||||
Integer value = (Integer) field.get(java.sql.Types.class);
|
||||
map.put(value, name);
|
||||
} catch (IllegalAccessException e) {
|
||||
} catch (IllegalAccessException ignore) {
|
||||
// skip
|
||||
}
|
||||
}
|
||||
return map;
|
||||
|
||||
@@ -341,7 +341,7 @@ public class ForkRunner extends BlockJUnit4ClassRunner {
|
||||
}
|
||||
try {
|
||||
closeable.close();
|
||||
} catch (IOException e) {
|
||||
} catch (IOException ignore) {
|
||||
// skip
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,8 @@ public final class ClassPreLoader {
|
||||
public static void preload() {
|
||||
try {
|
||||
preload(65535);
|
||||
} catch (Exception e) {
|
||||
} catch (Exception ignore) {
|
||||
// skip
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,6 +66,7 @@ public abstract class StreamChannel {
|
||||
try {
|
||||
openLatch.await();
|
||||
} catch (InterruptedException e) {
|
||||
// check Interrupted state
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,6 +74,7 @@ public abstract class StreamChannel {
|
||||
try {
|
||||
return openLatch.await(timeoutMillis, TimeUnit.MILLISECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
// check Interrupted state
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
+2
-1
@@ -29,7 +29,8 @@ public class ByteArrayOutputStreamTransport extends TTransport {
|
||||
if (out != null) {
|
||||
try {
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
} catch (IOException ignore) {
|
||||
// skip
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,7 +125,8 @@ class DefaultTBaseLocator implements TBaseLocator {
|
||||
try {
|
||||
tBaseLookup(type);
|
||||
return true;
|
||||
} catch (TException e) {
|
||||
} catch (TException ignore) {
|
||||
// skip
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user