Performance issue #395

Closed
sesaretah opened this Issue Mar 30, 2013 · 6 comments

Projects

None yet

4 participants

@sesaretah

I don't know this is related to node-http-proxy or node.js itself but when I burden a large amount of binary transfer to a simple proxy such as:

var http = require('http'),
    httpProxy = require('http-proxy');

httpProxy.createServer(function (req, res, proxy) {
  var buffer = httpProxy.buffer(req);
    var proxy = new httpProxy.HttpProxy({
        target: {
            host: req.headers['host'], 
            port: 80,
            buffer: buffer
        }
    });

    proxy.proxyRequest(req, res);
  }).listen(9001);

And I direct it to youtube (playing some video) the cpu usage goes to 99.9% and about 70% of memory. The machine runs latest version of Ubuntu server, node, and node-http-proxy on a 1GB VPS server from Linode.com.

@indexzero
Member

You're doing it wrong. You don't need to buffer because you aren't doing anything async:

var http = require('http'),
    httpProxy = require('http-proxy');

httpProxy.createServer(function (req, res, proxy) {
    var proxy = new httpProxy.HttpProxy({
        target: {
            host: req.headers['host'], 
            port: 80
        }
    });

    proxy.proxyRequest(req, res);
}).listen(9001);

The memory usage you are experiencing is by buffering some huge video.

@indexzero indexzero closed this Mar 31, 2013
@jaruba
jaruba commented Oct 16, 2015

I'm also trying to proxy a youtube video, based on @indexzero 's example, I tried:

httpProxy.createServer(function (req, res, proxy) {
    var proxy = new httpProxy.HttpProxy({
        target: "https://r5---sn-gqn-vu2e.googlevideo.com/videoplayback?fexp=9407478%2C9408710%2C9414764%2C9416126%2C9417707&sver=3&key=yt6&mm=31&mn=sn-gqn-vu2e&sparams=dur%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpcm2cms%2Cpl%2Cratebypass%2Crequiressl%2Csource%2Cupn%2Cexpire&mt=1444999139&pl=24&mv=m&ms=au&signature=E144E838F4A0B5567CE3704EF912495ECE5AD774.AC5E99BB8299C6AD368DC8D92710E9436945260F&ip=188.26.58.218&lmt=1364902684950193&itag=59&requiressl=yes&id=o-AEQoRJfV8mXAOQydN9X7DLmE1PDmqELi-9QXKLMWjdyE&pcm2cms=yes&source=youtube&dur=3952.547&mime=video%2Fmp4&upn=sB2Mp78sDuo&initcwndbps=4090000&ratebypass=yes&ipbits=0&expire=1445020829",
        secure: false
    });

    proxy.proxyRequest(req, res);
}).listen(9041);

and

httpProxy.createServer(function (req, res, proxy) {
    var proxy = new httpProxy.HttpProxy({
        target: {
            protocol: 'https',
            host: 'r5---sn-gqn-vu2e.googlevideo.com',
            port: 443,
            path: '/videoplayback?fexp=9407478%2C9408710%2C9414764%2C9416126%2C9417707&sver=3&key=yt6&mm=31&mn=sn-gqn-vu2e&sparams=dur%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpcm2cms%2Cpl%2Cratebypass%2Crequiressl%2Csource%2Cupn%2Cexpire&mt=1444999139&pl=24&mv=m&ms=au&signature=E144E838F4A0B5567CE3704EF912495ECE5AD774.AC5E99BB8299C6AD368DC8D92710E9436945260F&ip=188.26.58.218&lmt=1364902684950193&itag=59&requiressl=yes&id=o-AEQoRJfV8mXAOQydN9X7DLmE1PDmqELi-9QXKLMWjdyE&pcm2cms=yes&source=youtube&dur=3952.547&mime=video%2Fmp4&upn=sB2Mp78sDuo&initcwndbps=4090000&ratebypass=yes&ipbits=0&expire=1445020829'
        },
        secure: false
    });

    proxy.proxyRequest(req, res);
}).listen(9031);

but when I'm connecting to the new server, i'm getting:

Uncaught Error: Must provide a proper URL as target

The .googlevideo.com link works fine if I load it in the browser thought (it's the direct video link from a random youtube video)

Any hints on how I might get this working?

@jcrugzz
Member
jcrugzz commented Oct 16, 2015

@jaruba Please read the updated readme as this module has changed since this issue has been closed and has a different API

@jaruba
jaruba commented Oct 16, 2015

@jcrugzz thanks for answering, my first issue was that I indeed did not read the readme carefully the first time.. I had to proxy an entire website (not just a page), I got it working with:

var http = require('http'),
    httpProxy = require('http-proxy'),
    proxy = httpProxy.createProxyServer();

http.createServer(function (req, res) {
    proxy.web(req, res, {
        target: 'https://r5---sn-gqn-vu2e.googlevideo.com:443',
        secure: false
    });
}).listen();
@jaruba
jaruba commented Oct 16, 2015

@jcrugzz @indexzero I seem to have a different sort of problem now though, the proxy seems to be created successfully, so these links both work:

http://localhost:65462/videoplayback?fexp=9407535%2C9407705%2C9408710%2C9412539%2C9413279%2C9414764%2C9416126%2C9416768%2C9417707%2C9418199%2C9421391&upn=owxmlH_rplw&ratebypass=yes&source=youtube&expire=1445055195&lmt=1364902684950193&ms=au&mv=m&mt=1445033448&pcm2cms=yes&ip=188.26.58.218&sver=3&sparams=dur%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpcm2cms%2Cpl%2Cratebypass%2Crequiressl%2Csource%2Cupn%2Cexpire&id=o-AD9JcMOwaswu3ar-8-0j1_0_r_YBPw17MTYvvuyR6npv&signature=5ECD52FA620C6B24C688E105F03056695FFD5777.7742046CFB2D129FE1210669E198517A5AF732E0&mime=video%2Fmp4&requiressl=yes&itag=59&dur=3952.547&pl=24&initcwndbps=4035000&ipbits=0&mn=sn-gqn-vu2e&mm=31&key=yt6
http://127.0.0.1:65462/videoplayback?fexp=9407535%2C9407705%2C9408710%2C9412539%2C9413279%2C9414764%2C9416126%2C9416768%2C9417707%2C9418199%2C9421391&upn=owxmlH_rplw&ratebypass=yes&source=youtube&expire=1445055195&lmt=1364902684950193&ms=au&mv=m&mt=1445033448&pcm2cms=yes&ip=188.26.58.218&sver=3&sparams=dur%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpcm2cms%2Cpl%2Cratebypass%2Crequiressl%2Csource%2Cupn%2Cexpire&id=o-AD9JcMOwaswu3ar-8-0j1_0_r_YBPw17MTYvvuyR6npv&signature=5ECD52FA620C6B24C688E105F03056695FFD5777.7742046CFB2D129FE1210669E198517A5AF732E0&mime=video%2Fmp4&requiressl=yes&itag=59&dur=3952.547&pl=24&initcwndbps=4035000&ipbits=0&mn=sn-gqn-vu2e&mm=31&key=yt6

but when I change the server ip to my LAN ip, it just gives me a blank page (even from the same PC that creates the server, no errors in the console):

http://192.168.1.103:65462/videoplayback?fexp=9407535%2C9407705%2C9408710%2C9412539%2C9413279%2C9414764%2C9416126%2C9416768%2C9417707%2C9418199%2C9421391&upn=owxmlH_rplw&ratebypass=yes&source=youtube&expire=1445055195&lmt=1364902684950193&ms=au&mv=m&mt=1445033448&pcm2cms=yes&ip=188.26.58.218&sver=3&sparams=dur%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpcm2cms%2Cpl%2Cratebypass%2Crequiressl%2Csource%2Cupn%2Cexpire&id=o-AD9JcMOwaswu3ar-8-0j1_0_r_YBPw17MTYvvuyR6npv&signature=5ECD52FA620C6B24C688E105F03056695FFD5777.7742046CFB2D129FE1210669E198517A5AF732E0&mime=video%2Fmp4&requiressl=yes&itag=59&dur=3952.547&pl=24&initcwndbps=4035000&ipbits=0&mn=sn-gqn-vu2e&mm=31&key=yt6

what could cause this?

@jaruba
jaruba commented Oct 18, 2015

It was a ssl issue, I got it working with the example code at:
https://github.com/nodejitsu/node-http-proxy/blob/302d981dd2cf06dbf751b1f64e3dfea08d0f9476/examples/http/proxy-http-to-https.js

Awesome module, thanks. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment