首页 \ 问答 \ aio_write比ext4上的普通写入花费更多时间?(aio_write takes more time than plain write on ext4?)

aio_write比ext4上的普通写入花费更多时间?(aio_write takes more time than plain write on ext4?)

我有一个C程序,它编写32768个块,每个块大小为16K(总大小为512MB),运行3.18.1内核的系统上的ext4文件系统。 该程序的常规写入系统调用版本需要5.35秒来完成写入(由for循环之前和之后的gettimeofday测量)。 然而,该程序的async io版本需要以下时间:

  1. 排队所有aio_writes(32768 aio_writes):7.43秒
  2. 轮询完成每个IO请求:额外4.93秒

使用以下标志打开输出文件:O_WRONLY,O_CREAT,O_NONBLOCK

为什么异步io占用write()时间的两倍以上? 甚至时间到队列 - 异步 - 请求/时间 - 写 - 同步 - io是1.4。

由于有些人将其标记为偏离主题,我查看了定义并决定粘贴代码 - 这似乎是它应该被标记为主题的唯一原因。 我不是在问为什么代码不起作用,只是为什么aio比常规写入慢得多,特别是因为所有并行写入都是针对不同的块。 这是aio代码,后跟非aio代码:

AIO计划

#define MAX_AIO        (16384*2)
#define BUFSIZE        16384

struct mys {
    int status;
    struct aiocb aio;
};

void set_aiocb(struct mys *aio, int num, int fd)
{
    int i;

    for (i = 0; i < num; i++) {
        aio[i].aio.aio_fildes = fd;
        aio[i].aio.aio_offset = BUFSIZE * i;
        aio[i].aio.aio_buf = malloc(BUFSIZE);
        set_buf(aio[i].aio.aio_buf, BUFSIZE, i);
        aio[i].aio.aio_nbytes = BUFSIZE;
        aio[i].aio.aio_reqprio = fd;
        aio[i].aio.aio_sigevent.sigev_notify = SIGEV_NONE;
        aio[i].aio.aio_sigevent.sigev_signo = SIGUSR1;
        aio[i].aio.aio_sigevent.sigev_value.sival_ptr = &aio[i];
        aio[i].aio.aio_lio_opcode = 0;
        aio[i].status = EINPROGRESS;
    }
}

void main(void)
{
    int fd = open("/tmp/AIO", O_WRONLY | O_CREAT, 0666);
    int i, open_reqs = MAX_AIO;
    struct mys aio[MAX_AIO];
    struct timeval start, end, diff;

    set_aiocb(aio, MAX_AIO, fd);

    gettimeofday(&start, NULL);
    for (i = 0; i < MAX_AIO; i++)
        aio_write(&aio[i].aio);

    while (open_reqs > 0) {
        for (i = 0; i < MAX_AIO; i++) {
            if (aio[i].status == EINPROGRESS) {
                aio[i].status = aio_error(&(aio[i].aio));
                if (aio[i].status != EINPROGRESS)
                    open_reqs--;
            }
        }
    }
    gettimeofday(&end, NULL);
    timersub(&end, &start, &diff);
    printf("%d.%d\n", (int)diff.tv_sec, (int)diff.tv_usec);
}

常规IO程序

#define MAX_AIO        (16384*2)
#define BUFSIZE        16384

char buf[MAX_AIO][BUFSIZE];
void main(void)
{
    int i, fd = open("/tmp/NON_AIO", O_WRONLY | O_CREAT, 0666);
    struct timeval start, end, diff;

    gettimeofday(&start, NULL);
    for (i = 0; i < MAX_AIO; i++)
        write(fd, buf[i], BUFSIZE);
    gettimeofday(&end, NULL);
    timersub(&end, &start, &diff);
    printf("%d.%d\n", (int)diff.tv_sec, (int)diff.tv_usec);
}

I have a C program that writes 32768 blocks, each block is 16K size (total size of 512MB), to an ext4 filesystem on a system running 3.18.1 kernel. The regular write system call version of this program takes 5.35 seconds to finish the writes (as measured by gettimeofday before and after the for loop). The async io version of this program however takes the following times:

  1. to queue all the aio_writes (32768 aio_writes): 7.43 seconds
  2. poll to finish each IO request: additional 4.93 seconds

The output files are opened with these flags:O_WRONLY, O_CREAT, O_NONBLOCK

Why does async io take more than double the write() time? Even the Time-to-queue-async-io-request/time-to-write-sync-io is 1.4.

Since some people marked it off-topic, I looked at the definition and decided to paste the code - that seems to be the only reason why it should be marked off-topic. I am not asking why the code is not working, only why aio is much slower than regular writes, especially since all parallel writes are to different blocks. Here's the aio code, followed by the non-aio code:

AIO program

#define MAX_AIO        (16384*2)
#define BUFSIZE        16384

struct mys {
    int status;
    struct aiocb aio;
};

void set_aiocb(struct mys *aio, int num, int fd)
{
    int i;

    for (i = 0; i < num; i++) {
        aio[i].aio.aio_fildes = fd;
        aio[i].aio.aio_offset = BUFSIZE * i;
        aio[i].aio.aio_buf = malloc(BUFSIZE);
        set_buf(aio[i].aio.aio_buf, BUFSIZE, i);
        aio[i].aio.aio_nbytes = BUFSIZE;
        aio[i].aio.aio_reqprio = fd;
        aio[i].aio.aio_sigevent.sigev_notify = SIGEV_NONE;
        aio[i].aio.aio_sigevent.sigev_signo = SIGUSR1;
        aio[i].aio.aio_sigevent.sigev_value.sival_ptr = &aio[i];
        aio[i].aio.aio_lio_opcode = 0;
        aio[i].status = EINPROGRESS;
    }
}

void main(void)
{
    int fd = open("/tmp/AIO", O_WRONLY | O_CREAT, 0666);
    int i, open_reqs = MAX_AIO;
    struct mys aio[MAX_AIO];
    struct timeval start, end, diff;

    set_aiocb(aio, MAX_AIO, fd);

    gettimeofday(&start, NULL);
    for (i = 0; i < MAX_AIO; i++)
        aio_write(&aio[i].aio);

    while (open_reqs > 0) {
        for (i = 0; i < MAX_AIO; i++) {
            if (aio[i].status == EINPROGRESS) {
                aio[i].status = aio_error(&(aio[i].aio));
                if (aio[i].status != EINPROGRESS)
                    open_reqs--;
            }
        }
    }
    gettimeofday(&end, NULL);
    timersub(&end, &start, &diff);
    printf("%d.%d\n", (int)diff.tv_sec, (int)diff.tv_usec);
}

Regular IO program

#define MAX_AIO        (16384*2)
#define BUFSIZE        16384

char buf[MAX_AIO][BUFSIZE];
void main(void)
{
    int i, fd = open("/tmp/NON_AIO", O_WRONLY | O_CREAT, 0666);
    struct timeval start, end, diff;

    gettimeofday(&start, NULL);
    for (i = 0; i < MAX_AIO; i++)
        write(fd, buf[i], BUFSIZE);
    gettimeofday(&end, NULL);
    timersub(&end, &start, &diff);
    printf("%d.%d\n", (int)diff.tv_sec, (int)diff.tv_usec);
}

原文:https://stackoverflow.com/questions/28170110
更新时间:2023-04-18 17:04

最满意答案

<g:render template="/mail/css" /> 

将在grails-app\views\mail\_css.gsp查找模板,而不是grails-app\views\layouts\mail\_css.gsp


<g:render template="/mail/css" /> 

will look for the template at grails-app\views\mail\_css.gsp, not grails-app\views\layouts\mail\_css.gsp.

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。