Comments (1)
Read a lot of Postgres documentation about functions, indexing:
- https://www.postgresql.org/docs/9.1/sql-createindex.html
- https://www.postgresql.org/docs/9.1/sql-createfunction.html
- https://www.postgresql.org/docs/9.2/queries-table-expressions.html
- https://www.w3schools.com/sql/sql_distinct.asp
also looked around for articles. Probably the simplest to understand and try out was this:
- https://statsbot.co/blog/postgresql-query-optimization/
Took apart all the main queries and run them separately to find the slowest and found out that they were quite ok. So after that rewrote query that built the returning data into a function and that helped to bring down the cost, but performance got really slow. Finally concentrated on query order. So to first narrow down ID-s to return and after that get all data that is only related to these.
To get better picture from queries used: - http://tatiyants.com/pev/#/plans
Final results without adding any new indexes or altering DB structure (Run on local DB with about 30000 rows in Activities table, created by re-running all the tests over and over):
Query cost from: 30821841.70 -> 207202.78
Execution time 2247.545 -> 607.797 ms
Memory usage under load test described in this issue ~180MB -> ~40MB
Execution times under load test: - min 3815ms -> 832ms
- median 8062ms ->2281ms
- max 12332ms ->3859ms
from citizenos-api.
Related Issues (20)
- PRIVACY: Do not store IP address more than 4 years HOT 2
- Update E-mail tests to validate HTML HOT 1
- Topic invite flow error for existing User - POST /api/users/self/topics/:topicId/invites/users/:inviteId/accept
- Topic list loading is getting slow. HOT 1
- TECH DEPT: Remove send to parliament related parts from API code HOT 3
- INVITE API creates case sensitive e-mail accounts HOT 4
- Choose between accounts on login HOT 2
- Allow users to merge accounts HOT 2
- Separate contact e-mail and login e-mail HOT 2
- BUG: Topic invite email: wonky footer layout + translation HOT 3
- Public groups HOT 22
- Login invited users with correct account when using e-ID HOT 4
- Machine Learning and AI integrations HOT 2
- Adding topic to group sends confusing invite e-mail
- Only allow public topics inside public groups HOT 2
- Update /api/stats endpoint HOT 5
- Max characters for invite email - UX issue HOT 4
- Odd black bar showing on homepage on mobile HOT 1
- Error message is hard to understand HOT 3
- ID test cert is outdated, probably need to order a new test ID-card HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from citizenos-api.