[ad_1]
I’m curious why the efficiency of my logging routines (utilizing O_APPEND) are so poor on MacOS, and did some testing. The efficiency is kind of unhealthy. Is that this a identified downside with APFS?
These checks are on a Mac Mini 2018 (Intel) operating Sonoma 14.5.
(a) Inner SSD formatted as APFS. (And the efficiency is worse if the file already exists!)
bll-mac:/Volumes/Customers/bll/bdj4/src$ rm -f tt-out.txt; time $HOME/bdj4/src/tt & time $HOME/bdj4/src/tt &
actual 0m11.294s
person 0m0.073s
sys 0m6.144s
actual 0m11.391s
person 0m0.143s
sys 0m12.304s
(b) /Volumes/spare is an Exterior HDD formatted as HFS. (system data says the protocol is USB).
bll-mac:/Volumes/spare$ rm -f tt-out.txt; time $HOME/bdj4/src/tt & time $HOME/bdj4/src/tt &
actual 0m4.223s
person 0m0.058s
sys 0m2.681s
actual 0m4.241s
person 0m0.057s
sys 0m2.680s
(c) On the identical exterior HDD on an APFS partition.
bll-mac:/Volumes/Avail-big$ rm -f tt-out.txt; time $HOME/bdj4/src/tt & time $HOME/bdj4/src/tt &
actual 0m10.238s
person 0m0.136s
sys 0m11.497s
actual 0m10.239s
person 0m0.203s
sys 0m17.234s
(d) Only for comparability, on Linux, on an SSD (SATA).
bll-g7:bll$ time ./tt & time ./tt &
actual 0m2.213s
person 0m0.033s
sys 0m1.200s
actual 0m2.227s
person 0m0.047s
sys 0m1.228s
(e) And on MacOS, the inner SSD with O_APPEND off:
The velocity right here is extra cheap, although twice as gradual as Linux.
bll-mac:/Volumes/Customers/bll/bdj4/src$ rm -f tt-out.txt; time $HOME/bdj4/src/tt x & time $HOME/bdj4/src/tt x &
actual 0m2.316s
person 0m0.039s
sys 0m1.119s
actual 0m2.331s
person 0m0.118s
sys 0m3.339s
Code:
#embody <stdio.h>
#embody <stdlib.h>
#embody <stdbool.h>
#embody <string.h>
#embody <errno.h>
#embody <sys/varieties.h>
#embody <sys/stat.h>
#embody <fcntl.h>
#embody <unistd.h>
enum {
LCOUNT = 100000,
TCOUNT = 8,
};
int
fileSharedOpen (const char *fname, int appflag)
{
int fd;
int flags;
if (fname == NULL || ! *fname) {
return -1;
}
flags = O_WRONLY | O_CREAT;
if (appflag) = O_APPEND;
fd = open (fname, flags, 0600);
return fd;
}
ssize_t
fileSharedWrite (int fd, const char *knowledge, size_t len)
{
ssize_t rc;
rc = write (fd, knowledge, len);
return rc;
}
void
fileSharedClose (int fd)
{
shut (fd);
return;
}
void
course of (int flag)
{
int fd;
char tdata [400];
size_t len;
strcpy (tdata, "aaaaaaaaaaaaa");
strcat (tdata, "bbbbbbbbbbbbb");
strcat (tdata, "ccccccccccccc");
strcat (tdata, "n");
len = strlen (tdata);
fd = fileSharedOpen ("tt-out.txt", flag);
for (int i = 0; i < LCOUNT; ++i) {
fileSharedWrite (fd, tdata, len);
}
fileSharedClose (fd);
}
int
predominant (int argc, char *argv [])
{
int flag;
flag = true;
if (argc > 1) {
flag = false;
}
for (int i = 0; i < TCOUNT; ++i) {
pid_t pid;
pid = fork ();
if (pid != 0) {
course of (flag);
exit (0);
}
}
course of (flag);
return 0;
}
[ad_2]