perak / meteor-joins

Collection joins for Meteor
77 stars 7 forks source link

Waiting (TTFB) problem with join in Meteor HTTP web service? #2

Closed emehmet closed 9 years ago

emehmet commented 9 years ago

I wrote an HTTP webservice using webapp package of Meteor. I have a problem about waiting (TTFB): when I start the server program the first time I get a response within one second, but with time this response begins to increase; e.g. after 24 hours it takes 7 seconds and that continues to increase.

Client images link below:

img

WebApp.connectHandlers.use("/webhooks/takip", function(req, res, next) { res.setHeader("Content-Type", "Content-Type: text/json; charset=UTF8"); var durakid = req.query.id;

WebApp.connectHandlers.use("/webhooks/takip", function(req, res, next) { res.setHeader("Content-Type", "Content-Type: text/json; charset=UTF8"); var durakid = req.query.id;

var hat = hat_listesi.find();

akilli_takip.join(hat_listesi, "HATID", "hat", ["HATNO", "HATADI", "RENK"]);

var akilli = akilli_takip.find({ DURAKID: durakid }, { sort: { ARAC1SURE: 1 }, fields: { ARAC1HAREKET: 0, ARAC2HAREKET: 0, DURAKID: 0, SABLONID: 0, DURAKNO: 0, DURAKADI: 0, LATLNG: 0, ARAC1: 0, ARAC2: 0, ARAC1METRE: 0, ARAC2METRE: 0, DURAKCOORSIRA: 0 } }); var obj = { data: akilli.fetch() }; res.end(EJSON.stringify(obj)); });

perak commented 9 years ago

Hi, I believe problem is that you are calling join() function on each request. Your collections should be joined only once. I usually put joins in directory "/both/joins/joins.js". Once join is called, it is persistent, and any future call to find or findOne will return joined data On Jul 16, 2015 12:38, "emehmet" notifications@github.com wrote:

I wrote an HTTP webservice using webapp package of Meteor. I have a problem about waiting (TTFB): when I start the server program the first time I get a response within one second, but with time this response begins to increase; e.g. after 24 hours it takes 7 seconds and that continues to increase.

Client images link below:

img http://i.imgur.com/K0SnlJR.png

WebApp.connectHandlers.use("/webhooks/takip", function(req, res, next) { res.setHeader("Content-Type", "Content-Type: text/json; charset=UTF8"); var durakid = req.query.id;

WebApp.connectHandlers.use("/webhooks/takip", function(req, res, next) { res.setHeader("Content-Type", "Content-Type: text/json; charset=UTF8"); var durakid = req.query.id;

var hat = hat_listesi.find();

akilli_takip.join(hat_listesi, "HATID", "hat", ["HATNO", "HATADI", "RENK"]);

var akilli = akilli_takip.find({ DURAKID: durakid }, { sort: { ARAC1SURE: 1 }, fields: { ARAC1HAREKET: 0, ARAC2HAREKET: 0, DURAKID: 0, SABLONID: 0, DURAKNO: 0, DURAKADI: 0, LATLNG: 0, ARAC1: 0, ARAC2: 0, ARAC1METRE: 0, ARAC2METRE: 0, DURAKCOORSIRA: 0 } }); var obj = { data: akilli.fetch() }; res.end(EJSON.stringify(obj)); });

— Reply to this email directly or view it on GitHub https://github.com/perak/meteor-joins/issues/2.

perak commented 9 years ago

Or to redefine answer: joins should be defined in the same place/scope where collections are defined, and only once.

emehmet commented 9 years ago

Thnx your replies. It's worked. You are right. Good day.