Skip to content

Performance fix for non-static streaming data#728

Merged
gittiver merged 4 commits intoCrowCpp:masterfrom
jfmu:jfm-performance-fix-no-static-streaming
Jan 1, 2024
Merged

Performance fix for non-static streaming data#728
gittiver merged 4 commits intoCrowCpp:masterfrom
jfmu:jfm-performance-fix-no-static-streaming

Conversation

@jfmu
Copy link
Copy Markdown
Contributor

@jfmu jfmu commented Dec 6, 2023

I am using your project at work for controlling a high performance fpga project. Sometimes i want to peek into the data, and get a bunch of bytes from the device. This may vary from some several kilobytes to megabytes, depending on how much data i need.
I noticed that when i start pulling 20Megs or more the response is terribly slow (this is when it comes into Crow's streaming-handling). So i took a look. I believe using substr there is not so good, because of all the alloc/dealloc.
You can verify, use the code below:


int main()
{
    crow::SimpleApp app;

    std::string test;
    test.resize(1024*1024*20);

    for(int i = 0; i < 20*1024*1024; i++)
        test[i] = (char)(i % 255);

    FILE *fp = fopen("/tmp/testcmp", "wb");
    fwrite(test.data(), 1, 1024*1024*20, fp);
    fclose(fp);

    CROW_ROUTE(app, "/")([&test](const crow::request &req, crow::response &resp ){
            resp.add_header("Content-Length", std::to_string(20*1024*1024));
            resp.body = test;
            resp.end();
    });

    app.port(18080).run();
}

I write to /tmp/testcmp to verify the checksums with the data i get via curl: /usr/bin/time -f "+%E" curl http://localhost:18080/ > /tmp/test
With current Crow the transfer takes several seconds. With this patch it takes some milliseconds.

Thank you for the amazing work on Crow. I really like it (especially the json stuff).
Kind regards,
jfm

@gittiver gittiver requested review from The-EDev and gittiver January 1, 2024 21:13
@gittiver gittiver closed this Jan 1, 2024
@gittiver gittiver reopened this Jan 1, 2024
@gittiver gittiver merged commit f3e0846 into CrowCpp:master Jan 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants