emscripten-core/emscripten

Running a program which accepts stdin/stdout in Node.js causes it to consume 100% CPU+RAM

Open

#1,151 建立於 2013年5月7日

在 GitHub 查看
 (20 留言) (0 反應) (0 負責人)C++ (27,361 star) (3,519 fork)batch import
help wantedperformance

描述

Hi,

I am trying to build perl5 using emscripten and so far I have this:

https://github.com/shlomif/perl5-build-using-emscripten

However I'm running into problem with the perl "tryp.c" example, and could not find anything in a web search.

Please run the following script in an empty directory with "emcc" and "node" (from node-js) in the path:

#!/bin/bash

cat <<EOF > tryp.c
#include <stdio.h>
int
main(int argc, char **argv)
{
    char buf[1024];
    int i;
    char *bp = buf;
    while (1) {
    while ((i = getc(stdin)) != -1
           && (*bp++ = i) != '\n'
           && bp < &buf[1024])
    /* DO NOTHING */ ;
    *bp = '\0';
    fprintf(stdout, "%s", buf);
    fflush(stdin);
    if (i == -1)
        return 0;
    bp = buf;
    }
}
EOF

emcc --jcache -s TOTAL_MEMORY=134217728 -std=gnu99 -O2 -I . -m32 -o tryp.js tryp.c
node tryp.js


node ends up consuming 100% of CPU and gradually consumes more and more RAM. Can this be fixed?

Update: I am on Mageia Linux 3 Cauldron ( http://www.mageia.org/en/ ) with clang-3.2-5.mga3 , llvm-3.2-5.mga3 , nodejs-0.10.3-2.mga3 , etc.

Thanks!

-- @shlomif

貢獻者指南