0

我们必须对现有的 Web 应用程序实施监控模块。该应用程序的目的是记录在运行时执行的每个方法所花费的时间并保存到 2 个监控表中。由于应用程序中发生了很多方法调用,我们无法每次执行方法时都保存到表中。我们使用spring aop截取时间。我们使用redis缓存数据,每十分钟取一次数据从缓存中保存并保存在数据库中。但是 redis 似乎是一个麻烦的想法,因为它不断建立新的连接,这给应用程序带来了一场噩梦。有没有其他方法可以做到这一点。我们考虑写入文件并从中获取数据该文件是周期性的。但这似乎也是一个消耗资源的解决方案。

4

1 回答 1

1

I would suggest storing everything in your Java application. If all you want is a few stats, you can keep track of this information in a HashMap and write it every 10 minutes to the database from another thread. Min/Max/Avg time won't take much memory, and you can reset stats once it's written to the database.

If that doesn't suite your needs for some reason, Redis should be fast, and can even help you compute your statistics. I'd setup a connection pool to prevent it from making a new network connection each time. Then, I'd use asynchronous writes (pipelining) in your Redis client to speed up writes. Jedis and JRedis both support this.

于 2012-07-22T15:19:22.577 回答