简体   繁体   English

命令行 java 程序的磁盘 I/O

[英]disk I/O of a command line java program

I have a simple question, I've read up online but couldn't find a simple solution:我有一个简单的问题,我已经在网上阅读但找不到简单的解决方案:

I'm running a java program on the command line as follows which accesses a database:我在命令行上运行一个访问数据库的java程序,如下所示:

java -jar myProgram.jar

I would like a simple mechanism to see the number of disk I/Os performed by this program (on OSX).我想要一个简单的机制来查看这个程序(在 OSX 上)执行的磁盘 I/O 的数量。 So far I've come across iotop but how do I get iotop to measure the disk I/O of myProgram.jar?到目前为止,我遇到了iotop ,但是如何让iotop测量 myProgram.jar 的磁盘 I/O?

Do I need a profiler like JProfiler do get this information?我需要像JProfiler这样的分析器来获取这些信息吗?

iotop is a utility which gives you top n processes in descending order of IO consumption/utilization. iotop 是一个实用程序,它为您提供按 IO 消耗/利用率降序排列的前 n 个进程。

Most importantly it is a live monitoring utility which means its output changes every n sec( or time interval you specify).最重要的是,它是一个实时监控实用程序,这意味着它的输出每 n 秒(或您指定的时间间隔)更改一次。 Though you can redirect it to a file, you need to parse that file and find out meaningful data after plotting a graph.尽管您可以将其重定向到文件,但您需要在绘制图形后解析该文件并找出有意义的数据。

I would recommend to use sar.我建议使用 sar。 you can read more about it here你可以在这里阅读更多关于它的信息

It is the lowest level monitoring utility in linux/unix.它是 linux/unix 中最低级别的监控实用程序。 It will give you much more data than iotop.它将为您提供比 iotop 更多的数据。

best thing about sar is you can collect the data using a daemon when your program is running and then later analyze it using ksar关于 sar 最好的一点是,您可以在程序运行时使用守护进程收集数据,然后使用ksar对其进行分析

According to me, you can follow below approach,据我说,您可以按照以下方法,

  1. Start sar monitoring, collect sar data every n seconds.启动sar监控,每隔n秒收集一次sar数据。 value of n depends of approximate execution time of your program. n 的值取决于程序的大致执行时间。

example : if your program takes 10 seconds to execute then monitoring per sec is good but if your program takes 1hr to execute then monitor per min or 30 sec.示例:如果您的程序需要 10 秒执行,那么每秒监控一次很好,但如果您的程序需要 1 小时执行,那么每分钟或 30 秒监控一次。 This will minimize overhead of sar process and still your data is meaningful.这将最大限度地减少 sar 进程的开销,并且您的数据仍然是有意义的。

  1. Wait for some time (so that you get data before your program starts) and then start your program等待一段时间(以便在程序启动之前获取数据)然后启动程序

  2. end of your program execution程序执行结束

  3. wait for some time again (so that you get data after your program finishes)再次等待一段时间(以便在程序完成后获取数据)

  4. stop sar.停止萨尔。

Monitor/visualize sar data using ksar.使用 ksar 监控/可视化 sar 数据。 To start with, you check for disk utilization and then IOPS for a disk.首先,检查磁盘利用率,然后检查磁盘的 IOPS。

You can use Profilers for same thing but they have few drawbacks,您可以将 Profiler 用于相同的事情,但它们几乎没有缺点,

  1. They need their own agents (agents will have their own overhead)他们需要自己的代理(代理将有自己的开销)
  2. Some of them are not free.其中一些不是免费的。
  3. Some of them are not easy to set up.其中一些不容易设置。
  4. may or may not provide enough/required data.可能会或可能不会提供足够/所需的数据。

besides this IMHO, Using inbuilt/system level utilities is always beneficial.除了这个恕我直言,使用内置/系统级实用程序总是有益的。

I hope this was helpful.我希望这可以帮到你。

Your Java program will eventually be a process for host system so you need to filter out output of monitoring tool for your own process id.您的 Java 程序最终将成为主机系统的进程,因此您需要为自己的进程 ID 过滤掉监控工具的输出。 Refer Scripts section of this Blog Post请参阅此博客文章脚本部分

Also, even though you have tagged question with OsX but do mention in question that you are using OsX.此外,即使您使用 OsX 标记了问题,但确实提到您正在使用 OsX。

If you are looking for offline data - that is provided by proc filesystem in Unix bases systems but unfortunately that is missing in OSX , Where is the /proc folder on Mac OS X?如果您正在寻找脱机数据 - 由 Unix 基础系统中的proc文件系统提供,但不幸的是 OSX 中缺少该数据,Mac OS X 上的 /proc 文件夹在哪里?
/proc on Mac OS X /proc 在 Mac OS X 上

You might chose to write a small script to dump data from disk and process monitoring tools for your process id.您可能会选择编写一个小脚本来从磁盘和进程监控工具中为您的进程 ID 转储数据。 You can get your process id in script by process name, put script in a loop to look for that process name and start script before you execute your Java program.您可以通过进程名称在脚本中获取进程 ID,将脚本放入循环中以查找该进程名称并在执行 Java 程序之前启动脚本。 When script finds the said process, it will keep dumping relevant data from commands chosen by you at intervals decided by you.当脚本找到上述进程时,它将按照您决定的时间间隔不断地从您选择的命令中转储相关数据。 Once your programs ends ,log dumping script also terminates.一旦您的程序结束,日志转储脚本也会终止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM