@Test public void prototypeCreationIsFastEnough() { if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) { // Skip this test: Trace logging blows the time limit. return; } GenericApplicationContext ac = new GenericApplicationContext(); RootBeanDefinition rbd = new RootBeanDefinition(TestBean.class); rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE); rbd.getConstructorArgumentValues().addGenericArgumentValue("#{systemProperties.name}"); rbd.getPropertyValues().add("country", "#{systemProperties.country}"); ac.registerBeanDefinition("test", rbd); ac.refresh(); StopWatch sw = new StopWatch(); sw.start("prototype"); System.getProperties().put("name", "juergen"); System.getProperties().put("country", "UK"); try { for (int i = 0; i < 100000; i++) { TestBean tb = (TestBean) ac.getBean("test"); assertEquals("juergen", tb.getName()); assertEquals("UK", tb.getCountry()); } sw.stop(); } finally { System.getProperties().remove("country"); System.getProperties().remove("name"); } assertTrue( "Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 6000); }
@Test public void testGetStringParameterWithDefaultValueHandlingIsFastEnough() { Assume.group(TestGroup.PERFORMANCE); MockHttpServletRequest request = new MockHttpServletRequest(); StopWatch sw = new StopWatch(); sw.start(); for (int i = 0; i < 1000000; i++) { ServletRequestUtils.getStringParameter(request, "nonExistingParam", "defaultValue"); } sw.stop(); System.out.println(sw.getTotalTimeMillis()); assertTrue( "getStringParameter took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 250); }
protected void initDb() throws LiquibaseException { StopWatch watch = new StopWatch(); watch.start(); super.afterPropertiesSet(); watch.stop(); log.debug("Started Liquibase in {} ms", watch.getTotalTimeMillis()); }
private BibTrees fetchResultSet(int batchSize, BatchStatistics batchStatistics, Boolean isBibOnly) throws Exception { StopWatch stopWatch = new StopWatch(); stopWatch.start(); BibTrees bibTrees = new BibTrees(); int count = 0; if (batchSize <= 0) { return bibTrees; } while (bibResultSet.next()) { count++; BibTree bibTree = new BibTree(); Bib bib = fetchBibRecord(); bibTree.setBib(bib); if (!isBibOnly) { List<HoldingsTree> holdingsList = fetchHoldingsTreeForBib(Integer.parseInt(bib.getLocalId())); bibTree.getHoldingsTrees().addAll(holdingsList); batchStatistics.addHoldingsCount(holdingsList.size()); for (HoldingsTree holdingsTree : holdingsList) { batchStatistics.addItemCount(holdingsTree.getItems().size()); } } bibTrees.getBibTrees().add(bibTree); if (count == batchSize) { break; } } stopWatch.stop(); batchStatistics.addTimeTaken(stopWatch.getTotalTimeMillis()); batchStatistics.addBibCount(bibTrees.getBibTrees().size()); return bibTrees; }
/** Swagger Springfox configuration. */ @Bean @Profile("!" + Constants.SPRING_PROFILE_FAST) public Docket swaggerSpringfoxDocket(JHipsterProperties jHipsterProperties) { log.debug("Starting Swagger"); StopWatch watch = new StopWatch(); watch.start(); ApiInfo apiInfo = new ApiInfo( jHipsterProperties.getSwagger().getTitle(), jHipsterProperties.getSwagger().getDescription(), jHipsterProperties.getSwagger().getVersion(), jHipsterProperties.getSwagger().getTermsOfServiceUrl(), jHipsterProperties.getSwagger().getContact(), jHipsterProperties.getSwagger().getLicense(), jHipsterProperties.getSwagger().getLicenseUrl()); Docket docket = new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo) .genericModelSubstitutes(ResponseEntity.class) .forCodeGeneration(true) .genericModelSubstitutes(ResponseEntity.class) .ignoredParameterTypes(Pageable.class) .directModelSubstitute(java.time.LocalDate.class, String.class) .directModelSubstitute(java.time.ZonedDateTime.class, Date.class) .directModelSubstitute(java.time.LocalDateTime.class, Date.class) .select() .paths(regex(DEFAULT_INCLUDE_PATTERN)) .build(); watch.stop(); log.debug("Started Swagger in {} ms", watch.getTotalTimeMillis()); return docket; }
@Override protected void doFilterInternal( HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException { UrlPathHelper helper = new UrlPathHelper(); String suffix = helper.getPathWithinApplication(request); StopWatch stopWatch = new StopWatch(); stopWatch.start(); try { chain.doFilter(request, response); } finally { stopWatch.stop(); int status = getStatus(response); Object bestMatchingPattern = request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE); HttpStatus httpStatus = HttpStatus.OK; try { httpStatus = HttpStatus.valueOf(status); } catch (Exception ex) { // not convertible } if (bestMatchingPattern != null) { suffix = bestMatchingPattern.toString().replaceAll("[{}]", "-"); } else if (httpStatus.is4xxClientError()) { suffix = UNKNOWN_PATH_SUFFIX; } String gaugeKey = getKey("response" + suffix); MetricFilterAutoConfiguration.this.gaugeService.submit( gaugeKey, stopWatch.getTotalTimeMillis()); String counterKey = getKey("status." + status + suffix); MetricFilterAutoConfiguration.this.counterService.increment(counterKey); } }
// 同步所有服装款式 @Scheduled(cron = "20 0 3 * * *") public void syncAllCloth() { StopWatch sw = new StopWatch(); sw.start(); logger.info("===>> 开始同步服装"); this.henghuaService.syncAllCloth(); sw.stop(); logger.info("===>> 服装同步完毕,共耗时:" + sw.getTotalTimeMillis() + "ms"); }
// 同步所有样品数据 @Scheduled(cron = "10 0 3 * * *") public void syncAllSampleDetail() { StopWatch sw = new StopWatch(); sw.start(); logger.info("===>> 开始同步样品"); this.henghuaService.syncAllSampleDetail(); sw.stop(); logger.info("===>> 样品同步完毕,共耗时:" + sw.getTotalTimeMillis() + "ms"); }
/** Swagger Spring MVC configuration. */ @Bean public SwaggerSpringMvcPlugin swaggerSpringMvcPlugin(SpringSwaggerConfig springSwaggerConfig) { log.debug("Starting Swagger"); StopWatch watch = new StopWatch(); watch.start(); SwaggerSpringMvcPlugin swaggerSpringMvcPlugin = new SwaggerSpringMvcPlugin(springSwaggerConfig) .apiInfo(apiInfo()) .genericModelSubstitutes(ResponseEntity.class) .includePatterns(DEFAULT_INCLUDE_PATTERN); swaggerSpringMvcPlugin.build(); watch.stop(); log.debug("Started Swagger in {} ms", watch.getTotalTimeMillis()); return swaggerSpringMvcPlugin; }
@Override protected void doFilterInternal( HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException { StopWatch stopWatch = new StopWatch(); stopWatch.start(); String path = new UrlPathHelper().getPathWithinApplication(request); int status = HttpStatus.INTERNAL_SERVER_ERROR.value(); try { chain.doFilter(request, response); status = getStatus(response); } finally { stopWatch.stop(); recordMetrics(request, path, status, stopWatch.getTotalTimeMillis()); } }
@Around("within(@org.springframework.stereotype.Repository *)") public Object invoke(ProceedingJoinPoint joinPoint) throws Throwable { if (this.enabled) { StopWatch sw = new StopWatch(joinPoint.toShortString()); sw.start("invoke"); try { return joinPoint.proceed(); } finally { sw.stop(); synchronized (this) { this.callCount++; this.accumulatedCallTime += sw.getTotalTimeMillis(); } } } else { return joinPoint.proceed(); } }
public static void main(String[] args) throws ParseException { StopWatch sw2 = new StopWatch(); sw2.start(); logger.info("Fare Start load spring configuration file ,Time= " + new Date()); ClassPathXmlApplicationContext applicationcontext = new ClassPathXmlApplicationContext( new String[] { "spring/applicationContext-common.xml", "spring/applicationContext-db-ec.xml", "spring/applicationContext-dubbo.xml", "spring/applicationContext-mongodb.xml", "spring/applicationContext-cache-process.xml", "spring/applicationContext-db-tax.xml" }); logger.info("Fare End Load spring conf configuration ,Time= " + new Date()); // 启动http Server new EmbedHTTPServer(new DefaultHttpHandler(), FareContants.HTTP_PORT); sw2.stop(); logger.info("Fare System Start Time :" + sw2.getTotalTimeMillis()); sparkFare(applicationcontext); logger.info("Fare is Running...."); }
@Test public void testGetUser() throws Exception { StopWatch stopwatch = new StopWatch(); stopwatch.start(); GithubUser foo = githubService.getUser("foo"); stopwatch.stop(); long duration = stopwatch.getTotalTimeMillis(); assertThat(foo).isNotNull(); assertThat(foo.getUser()).isNotNull(); assertThat(foo.getUser().getLogin()).isEqualTo("foo"); assertThat(foo.getUser().getName()).isEqualTo("foo bar"); assertThat(foo.getFollowers()).hasSize(3).extracting("name").contains("bar", "qix", "baz"); assertThat(foo.getRepositories()).hasSize(2).extracting("name").contains("foo", "bar"); // duration should be at least 300ms & max 400ms with overhead assertThat(duration).isGreaterThanOrEqualTo(300); assertThat(duration).isLessThanOrEqualTo(400); }
/** Swagger Springfox configuration. */ @Bean public Docket swaggerSpringfoxDocket() { log.debug("Starting Swagger"); StopWatch watch = new StopWatch(); watch.start(); Docket docket = new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .genericModelSubstitutes(ResponseEntity.class) .forCodeGeneration(true) .genericModelSubstitutes(ResponseEntity.class) .directModelSubstitute(org.joda.time.LocalDate.class, String.class) .directModelSubstitute(org.joda.time.LocalDateTime.class, Date.class) .directModelSubstitute(org.joda.time.DateTime.class, Date.class) .directModelSubstitute(java.time.LocalDate.class, String.class) .directModelSubstitute(java.time.ZonedDateTime.class, Date.class) .directModelSubstitute(java.time.LocalDateTime.class, Date.class) .select() .paths(regex(DEFAULT_INCLUDE_PATTERN)) .build(); watch.stop(); log.debug("Started Swagger in {} ms", watch.getTotalTimeMillis()); return docket; }
/** * 方法用途: <br> * 实现步骤: <br> * * @param ctx */ @RequestMapping(value = "ticket/v2") public void ticket(HttpServletRequest request, HttpServletResponse response) { StopWatch stopWatch = new StopWatch(); stopWatch.start(); log.debug("process in ApiServlet.ticket start......"); response.setContentType("text/html; charset=UTF-8"); PrintWriter writer = null; String returnStr = ""; String suffix = ""; String requestPath = request.getRequestURL().toString(); String ip = ApiConstant.getIpAddr(request); log.info("IP:" + ip); log.debug("requestPath:" + requestPath); Map<String, String> map = getParamterMap(request); String channelCode = map.get("channelCode"); String requestName = map.get("method"); try { writer = response.getWriter(); String requestCode = requestName.substring(0, requestName.indexOf(".")); suffix = requestName.substring(requestName.indexOf(".") + 1, requestName.length()); map.put("suffix", suffix); // 将后缀添加map,方便后续操作 // 校验参数 错误会抛出异常 this.checkParam(map); map.put("seckey", "根据不同渠道key不同,TODO"); // 请求业务码 : 参数、接口名称(如:queryFilms.json) returnStr = requestHttpProcess(map, requestName); } catch (BusinessException e) { returnStr = ApiConstant.replaceBack500( ErrorCodeEnum.ERROR.getErrorCode() + "", e.getMessage(), suffix); log.error("ApiServlet.doPost 操作异常: " + e.getMessage()); } catch (Exception e) { returnStr = ApiConstant.replaceBack500( ErrorCodeEnum.E_SYSTEM.getErrorCode() + "", ErrorCodeEnum.E_SYSTEM.getCodeName(), suffix); log.error("ApiServlet.doPost 操作异常: ", e); } log.debug("返回报文:" + returnStr); try { stopWatch.stop(); String logKeywords = "[channelCode渠道:" + channelCode + ",method接口:" + requestName + "]"; loggerUtil.logInfoInterface( logKeywords, requestPath, map.toString(), "", stopWatch.getTotalTimeMillis()); } catch (Exception e) { returnStr = ApiConstant.replaceBack500( ErrorCodeEnum.E_SYSTEM.getErrorCode() + "", ErrorCodeEnum.E_SYSTEM.getCodeName(), suffix); log.error("转换UTF-8异常:", e); } writer.write(returnStr); }