English 中文(简体)
Log response-time in restlet-based webservice
原标题:

What is the simplest way to log the response-time for a restlet-based webservice?

I want to make sure that our webservice has a reasonable response time. So I want to be able to keep an eye on response times, and do something about the requests that take too long.

The closest thing I could find is this recipe: http://www.naviquan.com/blog/restlet-cookbook-log, it explains how to change the log format. But there doesn t seem to be a parameter for response times, so probably a completely different approach is needed.

最佳回答

Well, the simplest way of logging response times is, of course, by calling System.getCurrentTimeMillis() at the start of your restlet, and then again at the end of your restlet and logging the difference. That won t of course give you the framework overhead, and I suspect it s much more naive and trivial than you are after.

I m posting it, however, because after 10 days nobody has answered you, and I suspect it s because everybody s quietly thinking

"Can t you just use System.getCurrentTimeMillis()? No, surely that s way too dumb an answer; I d look like an idiot if I said that. I ll just wait for someone else to make the first post."

问题回答

I don t think logging is the way to go here, at least not any of the types of logging built into Restlet or the Java API. Those are intended for either programmatic debugging-oriented logging or access logging intended to provide statistics on which resources are being used and by whom. But the real problem is that you wouldn t be measuring the real-world experience which your users would have of your service.

If you want to measure the response times that your users will be experiencing, then you really need to have an approach to sampling which lives outside of your application stack, and ideally outside of your datacenter, so as to simulate as closely as possible the real-world conditions under which your users will be using your service.

If you only need to test the results of fairly straightforward GET and POST requests, a service like Pingdom would probably suffice. If your service is more complex, then you may need to write your own sampling app/script, which could serve as a proxy from Pingdom, et al, to your actual service. You should host the sampling proxy on a separate server from your actual service. Google s App Engine might be convenient for this.

One way to do this I suppose is to use the Codehale s metric API. Just add an annotation @Timed(name="sampleApiName") to your API declaration.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签