emscripten-core / emscripten-core/emscripten

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

Open
#1,151 20 comments 0 reactions 0 assignees View on GitHub
help wanted performance
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

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:

``` bash
#!/bin/bash

cat < tryp.c
#include
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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.