question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

nodejs + postgresql way too slow

See original GitHub issue

I’m not sure whether this is an issue with pg or not, but I am not being able to get a reasonably enough fast app using node-postgres (pg). I wrote a question on stackoverflow but it seems nobody was able to help me.

Here is the post on stack overflow. I thought it would be better just to link it instead of duplicating everything here. (Just tell me in case it would be better to have the full problem described here)

Thanks in advance for any help.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
brianccommented, Oct 3, 2014

First thing I can see is you’re still running the query twice on every request. Remove all that stuff about the QueryStream and just call res.send(result.rows) directly. There’s no reason to go through the hoops of streaming results to the client if there are only 1,000 rows. Possibly after 10k rows you’ll start seeing an advantage to streaming, but for the most part it only becomes apparent when you’re moving massive amounts of data. In your example you’re still selecting the entire 1,000 row result set into memory, disregarding it, and then doing the query a 2nd time and streaming the results to the client.

0reactions
FernandoBassocommented, Oct 10, 2014

All right. I’ll keep your recommendation in mind in my next attempts to understand what is going on. Thanks a lot for your help and time. I really appreciate it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - nodejs + postgresql way too slow - Stack Overflow
When I run apache bench on it, it get only about four requests per second. If I run the same query in php/apache...
Read more >
[Node] Slow queries for PostgreSQL on NodeJS agent
Hello! I recently implemented the New Relic agent in my application, and would like to get more information about SQL queries that are...
Read more >
This is why your Node.js application is slow
The simple problem with it is that it is capable of slowing down your application greatly when not correctly used. Whenever a promise...
Read more >
Optimizing PostgreSQL query performance - Prisma
The first thing you should do is verify the current state of slow query logging. If slow query logging is already enabled, you...
Read more >
Node = Slow? : r/node - Reddit
Most back end stuff is high latency - fetch from disk or SQL database, for example. In those cases, it doesn't matter that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found