java - How to log performance result of Restful API call using dropwizard as a framework? -
i followed link first rest api create restful api.
i can view response on hitting url : http://localhost:8080/hello-world?name=xxx.
now want test performance of api using completion service , log response time each hit in human readable format.
how can achieve this?
this easy do. there 2 methods that:
do metrics or logging. in resource, can use metrics created , write out whatever want, e.g:
@get public string hello() { timer timer = service.timer("test"); try(context t = timer.time()) { return "hello world"; } }
alternatively measure time , log somewhere, e.g:
@get public string hello() { long currenttimemillis = system.currenttimemillis(); try { return "hello world"; } { log.info("request took: " + (system.currenttimemillis() - currenttimemillis) + " ms"); } }
the dw alternative of doing use timed annotation, like:
@get @timed(name="wohoho") public string hello() { return "hello world"; }
this equal manual approach (the name of metric "wohoho").
additionally need report on metrics, example this:
consolereporter.forregistry(environment.metrics()).build().start(10, timeunit.seconds);
this report every ten seconds, , result looks like:
-- timers -------------------------------------------- dw.helloresource.wohoho count = 9 mean rate = 0.13 calls/second 1-minute rate = 0.11 calls/second 5-minute rate = 0.03 calls/second 15-minute rate = 0.01 calls/second min = 0.16 milliseconds max = 5.41 milliseconds mean = 0.90 milliseconds stddev = 1.43 milliseconds median = 0.46 milliseconds 75% <= 0.59 milliseconds 95% <= 5.41 milliseconds 98% <= 5.41 milliseconds 99% <= 5.41 milliseconds 99.9% <= 5.41 milliseconds
and that's have do.
using metrics preferred way, because e.g. submit graphite , plot performance on time among other things.
hope helps,
artur
Comments
Post a Comment