简体   繁体   English

通过自动杀死文件/行中的C程序来测试持久性?

[英]Testing durability by automatically killing a C program at file/line?

I'm writing a bit of software that uses the fsync() system call to ensure a file is persisted to disk. 我正在编写一些使用fsync()系统调用的软件,以确保将文件持久保存到磁盘。 I've done this before, and I'm aware of various "gotchas" you need to be aware of (ie, when replacing a file, you need to fsync() the file, issue a rename() , then fsync() the containing directory. Coding the software that durably writes files to disk is fine. 我之前已经做过,而且我知道您需要注意的各种“陷阱”(即,在替换文件时,您需要先fsync()文件,先发出rename() ,然后再执行fsync()将包含持久性文件写入磁盘的软件编码就可以了。

Testing the software is another matter. 测试软件是另一回事。 I want to verify that it operates correctly in the face of, eg, power outages. 我想验证它在遇到断电等情况下是否可以正常运行。 My physical reflexes are pretty good, but not quite good enough to unplug the power cable between two CPU instructions. 我的身体反应还不错,但还不足以拔掉两条CPU指令之间的电源线。

How should I test the durability of a C program that writes to disk? 我应该如何测试写入磁盘的C程序的持久性?

(As implied by the title, I'm assuming you use some sort of debugger-like software, perhaps using ptrace() , to automatically kill your program at particular files/lines, as listed in the debugging information of the executable.) (正如标题所暗示的,我假设您使用某种类似于调试器的软件,也许使用ptrace()来自动ptrace()程序在特定文件/行的位置,如可执行文件的调试信息中所述。)

Be prepared that you cannot save 100% data into the disk in the case of unforeseen events random events such as power outages under normal circumstances. 请做好准备,以防万一发生不可预见的事件(例如在正常情况下停电等随机事件),无法将100%的数据保存到磁盘中。 However, the probability can be improved by various ways - such as writing to disk in chunks. 但是,可以通过各种方式来提高概率-例如,分块写入磁盘。 The size of chunk be such that if this is not saved in the disk then either some parts of it could be recoverable after restart of power or ignored safely. 块的大小应确保如果未将其保存在磁盘中,则其部分内容可以在重新启动电源后恢复,也可以安全地忽略。 The size of chunk shall also depend on disk cache which will ensure data is quickly written and the rate of data stream that program reads. 块的大小还应取决于磁盘缓存,这将确保数据被快速写入以及程序读取的数据流速率。 Data recovery can be implemented by designing your HW/SW such that in case of power outage, there is some sort of backup power in the system. 通过设计您的硬件/软件,可以实现数据恢复,以便在断电的情况下,系统中有某种备用电源。 The design will either allow enough time to system to signal SW to complete saving of remaining data if any or, data remain stored in ram exclusive for this purpose until main power to cpu returns. 该设计将允许系统有足够的时间向系统发送信号,以向SW发出信号以完成剩余数据的保存(如果有的话),或者为此目的将数据保留存储在ram中,直到返回给CPU的主电源为止。 There are several testing ideas, one of them can be to perform disk write operations in a thread and start/kill the thread from main thread in a loop at rate as per your requirement. 有几种测试思路,其中一种可能是在线程中执行磁盘写操作,并根据需要以一定的速率在循环中从主线程启动/杀死线程。

Type of test that you are looking for are - Load test and stress test. 您正在寻找的测试类型是-负载测试和压力测试。 Load test will test if your application is able to perform when huge amount of data needs to be written on disk very frequently. 当需要非常频繁地将大量数据写入磁盘时,负载测试将测试您的应用程序是否能够执行。 This requires you to simulate the behaviour by providing it input externally eg. 这要求您通过从外部提供输入来模拟行为,例如。 via a test application simulating read data source. 通过模拟读取数据源的测试应用程序。 Stress test will test the behavior of program when CPU utilization is 100% in the system or there is no memory left in the system ram or disk. 当系统中的CPU利用率为100%或系统内存或磁盘中没有剩余内存时,压力测试将测试程序的行为。 strees-ng tool can be used for simulating cpu load scenarios. strees-ng工具可用于模拟cpu负载情况。 Please see [link] ( https://www.tecmint.com/linux-cpu-load-stress-test-with-stress-ng-tool/ ) .Hope it helps. 请参阅[链接]( https://www.tecmint.com/linux-cpu-load-stress-test-with-stress-ng-tool/ )。希望它会有所帮助。

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

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