SlideShare une entreprise Scribd logo
1  sur  22
Measuring is key.
We need facts to ensure
we’ve improved the system.
Previous years talks.
Odoo logs
Easiest starting point
"POST /mail/init_messaging HTTP/1.0" 200 - 129 0.542 0.952
Last 3 figures are:
● Number of SQL queries
● Time spent on SQL queries
● Time spent on method excluding sql
Odoo profiling method
● Built in profiler
from odoo.tools.misc import profile
from datetime import datetime
[...]
@profile("/tmp/profile_my_method%s.cprof" % datetime.now().isoformat())
def my_method(self):
[...]
● Open result in snakeviz
Other profiling methods:
● pyFlame
● pySpy
And now the SQL side.
log_destination = 'csvlog'
logging_collector = on
log_directory =
'/var/log/postgresql/pg_log/'
log_filename = 'postgresql-%Y-%m-
%d_%H%M%S.log'
log_min_duration_statement = 0
log_line_prefix = '%t [%p-%l] %q%u@%d '
lc_messages = 'en_US.UTF-8'
And analyse with pgbadger
➔ Require postgresql config access
➔ Choose level with
log_min_duration_statement
➔ HTML report as output
➔ Time consuming queries
◆ Per execution
◆ Due to the number of executions
Log with
PostgreSQL
Most Odoo SQL queries
were simple
SELECT id
FROM module_table
WHERE search_domain
AND record_rules
ORDER BY order_by;
SELECT field
FROM module_table
WHERE id=ANY([...]);
UPDATE module_table
SET field=value
WHERE id IN ([...]);
➔ How is
self.search([(‘field1_id.field2_ids.name’,
‘=’, ‘whatever’)]) evaluated?
◆ 13.0 VS 14.0
◆ https://github.com/odoo/odoo/pull/52403
◆ JOIN
➔ SELECT id with criterias
➔ SELECT field WHERE id
Optimise SQL Query
Need to know how PostgreSQL executes the query
explain analyse
SELECT sequence_prefix
FROM account_move
WHERE journal_id = 140
AND name != '/'
AND date_trunc('year', date) = date_trunc('year', '2017-10-16'::date)
AND id != 1129331
ORDER BY id DESC;
● Explain
● Explain (analyse/analyze, buffers, format=json)
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Index Scan using account_move_sequence_index2 on account_move (cost=0.42..94250.51 rows=550 width=12) (actual time=58.451..59.917 rows=1494 loops=1)
Index Cond: (journal_id = 140)
Filter: (((name)::text <> '/'::text) AND (id <> 1129331) AND (date_trunc('year'::text, (date)::timestamp with time zone) = date_trunc('year'::text, ('2017-10-16'::date)::timestamp
with time zone)))
Rows Removed by Filter: 110010
Planning time: 0.920 ms
Execution time: 59.973 ms
(6 rows)
explain analyse
SELECT sequence_prefix
FROM account_move
WHERE journal_id = 140
AND name != '/'
AND date_trunc('year', date) = date_trunc('year', '2017-10-16'::date)
AND id != 1129331
ORDER BY id DESC;
CREATE INDEX ON account_move(
journal_id,
date_trunc('year'::text, date::timestamp with time zone),
id DESC
)
WHERE name::text <> '/'::text;
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Index Scan using account_move_sequence_index2 on account_move (cost=0.42..94250.51 rows=550 width=12) (actual time=58.451..59.917 rows=1494 loops=1)
Index Cond: (journal_id = 140)
Filter: (((name)::text <> '/'::text) AND (id <> 1129331) AND (date_trunc('year'::text, (date)::timestamp with time zone) = date_trunc('year'::text, ('2017-10-16'::date)::timestamp
with time zone)))
Rows Removed by Filter: 110010
Planning time: 0.920 ms
Execution time: 59.973 ms
(6 rows)
ERROR: functions in index expression must be marked IMMUTABLE
explain analyse SELECT sequence_prefix FROM account_move WHERE journal_id = 140 AND name != '/' AND date_trunc('year', date) =
date_trunc('year', '2017-10-16'::date) AND id != 1129331 ORDER BY id DESC;
VS
explain analyse SELECT sequence_prefix FROM account_move WHERE journal_id = 140 AND name != '/' AND date_trunc('year',
date::timestamp without time zone) = date_trunc('year', '2017-10-16'::date) AND id != 1129331 ORDER BY id DESC;
Execution time: 4.777 ms
VS
explain analyse SELECT sequence_prefix FROM account_move WHERE journal_id = 140 AND name != '/' AND date_trunc('year',
date::timestamp without time zone) = date_trunc('year', '2017-10-16'::date) AND id != 1129331 ORDER BY id DESC LIMIT 1;
Execution time: 49.815 ms
# create index on account_move(journal_id, date_trunc('year'::text, date::timestamp without time zone)) WHERE name::text <>
'/'::text;
CREATE INDEX
# explain analyse SELECT sequence_prefix FROM account_move WHERE journal_id = 140 AND name != '/' AND date_trunc('year',
date::timestamp without time zone) = date_trunc('year', '2017-10-16'::date) AND id != 1129331 ORDER BY id DESC;
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Sort (cost=570.59..571.94 rows=538 width=12) (actual time=3.479..3.520 rows=1494 loops=1)
Sort Key: id DESC
Sort Method: quicksort Memory: 165kB
-> Index Scan using account_move_journal_id_date_trunc_idx on account_move (cost=0.43..546.19 rows=538 width=12) (actual time=0.179..2.841 rows=1494 loops=1)
Index Cond: ((journal_id = 140) AND (date_trunc('year'::text, (date)::timestamp without time zone) = date_trunc('year'::text, ('2017-10-16'::date)::timestamp with time
zone)))
Filter: (id <> 1129331)
Planning time: 1.048 ms
Execution time: 3.620 ms
(8 rows)
# explain analyse SELECT sequence_prefix FROM account_move WHERE journal_id = 140 AND name != '/' AND date_trunc('year',
date::timestamp without time zone) = date_trunc('year', '2017-10-16'::date) AND id != 1129331 ORDER BY id DESC limit 1;
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=0.42..172.74 rows=1 width=12) (actual time=42.422..42.423 rows=1 loops=1)
-> Index Scan using account_move_sequence_index2 on account_move (cost=0.42..92705.85 rows=538 width=12) (actual time=42.421..42.421 rows=1 loops=1)
Index Cond: (journal_id = 140)
Filter: (((name)::text <> '/'::text) AND (id <> 1129331) AND (date_trunc('year'::text, (date)::timestamp without time zone) = date_trunc('year'::text, ('2017-10-
16'::date)::timestamp with time zone)))
Rows Removed by Filter: 109954
Planning time: 0.263 ms
Execution time: 42.443 ms
(7 rows)
Beware the “limit 1”
SQL Constraints
Faster than python ones.
Harder to update.
Update once per
transaction
# timing
Timing is on.
# begin;
BEGIN
Time: 0.147 ms
# update account_move set name='nse'
where id=6;
UPDATE 1
Time: 2.696 ms
# update account_move set name='nse'
where id=6;
UPDATE 1
Time: 377.396 ms
# timing
Timing is on.
# update account_move set name='nse' where
id=6;
UPDATE 1
Time: 2.656 ms
# update account_move set name='nse' where
id=6;
UPDATE 1
Time: 2.621 ms
.flush() !
Storing
Related field.
Compute Stored and
not Stored fields in
the same method.
Compute
Translatable fields
Thank You

Contenu connexe

Tendances

Why and how to develop OpenERP test scenarios (in python and using OERPScenar...
Why and how to develop OpenERP test scenarios (in python and using OERPScenar...Why and how to develop OpenERP test scenarios (in python and using OERPScenar...
Why and how to develop OpenERP test scenarios (in python and using OERPScenar...
Odoo
 
Odoo 12 Functional Training
Odoo 12 Functional TrainingOdoo 12 Functional Training
Odoo 12 Functional Training
Mohamed Elbagoury
 
Odoo Accounting Roadmap
Odoo Accounting RoadmapOdoo Accounting Roadmap
Odoo Accounting Roadmap
Odoo
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
Command Prompt., Inc
 

Tendances (20)

Security: Odoo Code Hardening
Security: Odoo Code HardeningSecurity: Odoo Code Hardening
Security: Odoo Code Hardening
 
Asynchronous JS in Odoo
Asynchronous JS in OdooAsynchronous JS in Odoo
Asynchronous JS in Odoo
 
An in Depth Journey into Odoo's ORM
An in Depth Journey into Odoo's ORMAn in Depth Journey into Odoo's ORM
An in Depth Journey into Odoo's ORM
 
New Framework - ORM
New Framework - ORMNew Framework - ORM
New Framework - ORM
 
Tier Validation Workflows
Tier Validation WorkflowsTier Validation Workflows
Tier Validation Workflows
 
Why and how to develop OpenERP test scenarios (in python and using OERPScenar...
Why and how to develop OpenERP test scenarios (in python and using OERPScenar...Why and how to develop OpenERP test scenarios (in python and using OERPScenar...
Why and how to develop OpenERP test scenarios (in python and using OERPScenar...
 
Odoo icon smart buttons
Odoo   icon smart buttonsOdoo   icon smart buttons
Odoo icon smart buttons
 
Odoo 12 Functional Training
Odoo 12 Functional TrainingOdoo 12 Functional Training
Odoo 12 Functional Training
 
Odoo - Business intelligence: Develop cube views for your own objects
Odoo - Business intelligence: Develop cube views for your own objectsOdoo - Business intelligence: Develop cube views for your own objects
Odoo - Business intelligence: Develop cube views for your own objects
 
Odoo Accounting Roadmap
Odoo Accounting RoadmapOdoo Accounting Roadmap
Odoo Accounting Roadmap
 
ODOO Logistics
ODOO LogisticsODOO Logistics
ODOO Logistics
 
Odoo (OpenERP) Manufacturing Process
Odoo (OpenERP) Manufacturing ProcessOdoo (OpenERP) Manufacturing Process
Odoo (OpenERP) Manufacturing Process
 
How to Design Resilient Odoo Crons
How to Design Resilient Odoo CronsHow to Design Resilient Odoo Crons
How to Design Resilient Odoo Crons
 
Instant Printing of any Odoo Report or Shipping Label
Instant Printing of any Odoo Report or Shipping LabelInstant Printing of any Odoo Report or Shipping Label
Instant Printing of any Odoo Report or Shipping Label
 
Odoo experience 2022
Odoo experience 2022Odoo experience 2022
Odoo experience 2022
 
Odoo Experience 2018 - Code Profiling in Odoo
Odoo Experience 2018 - Code Profiling in OdooOdoo Experience 2018 - Code Profiling in Odoo
Odoo Experience 2018 - Code Profiling in Odoo
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
Budget Control with mis_builder 3 (2017)
Budget Control with mis_builder 3 (2017)Budget Control with mis_builder 3 (2017)
Budget Control with mis_builder 3 (2017)
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
Odoo's Test Framework - Learn Best Practices
Odoo's Test Framework - Learn Best PracticesOdoo's Test Framework - Learn Best Practices
Odoo's Test Framework - Learn Best Practices
 

Similaire à Common Performance Pitfalls in Odoo apps

Writing efficient sql
Writing efficient sqlWriting efficient sql
Writing efficient sql
j9soto
 
Postgres performance for humans
Postgres performance for humansPostgres performance for humans
Postgres performance for humans
Craig Kerstiens
 
Database Development Replication Security Maintenance Report
Database Development Replication Security Maintenance ReportDatabase Development Replication Security Maintenance Report
Database Development Replication Security Maintenance Report
nyin27
 
Oracle Diagnostics : Explain Plans (Simple)
Oracle Diagnostics : Explain Plans (Simple)Oracle Diagnostics : Explain Plans (Simple)
Oracle Diagnostics : Explain Plans (Simple)
Hemant K Chitale
 

Similaire à Common Performance Pitfalls in Odoo apps (20)

Tibero sql execution plan guide en
Tibero sql execution plan guide enTibero sql execution plan guide en
Tibero sql execution plan guide en
 
Basic Query Tuning Primer - Pg West 2009
Basic Query Tuning Primer - Pg West 2009Basic Query Tuning Primer - Pg West 2009
Basic Query Tuning Primer - Pg West 2009
 
Basic Query Tuning Primer
Basic Query Tuning PrimerBasic Query Tuning Primer
Basic Query Tuning Primer
 
query_tuning.pdf
query_tuning.pdfquery_tuning.pdf
query_tuning.pdf
 
SQLチューニング総合診療Oracle CloudWorld出張所
SQLチューニング総合診療Oracle CloudWorld出張所SQLチューニング総合診療Oracle CloudWorld出張所
SQLチューニング総合診療Oracle CloudWorld出張所
 
Powering Heap With PostgreSQL And CitusDB (PGConf Silicon Valley 2015)
Powering Heap With PostgreSQL And CitusDB (PGConf Silicon Valley 2015)Powering Heap With PostgreSQL And CitusDB (PGConf Silicon Valley 2015)
Powering Heap With PostgreSQL And CitusDB (PGConf Silicon Valley 2015)
 
Date data type and Globalization in Oracle
Date data type and Globalization in OracleDate data type and Globalization in Oracle
Date data type and Globalization in Oracle
 
A few things about the Oracle optimizer - 2013
A few things about the Oracle optimizer - 2013A few things about the Oracle optimizer - 2013
A few things about the Oracle optimizer - 2013
 
Введение в современную PostgreSQL. Часть 2
Введение в современную PostgreSQL. Часть 2Введение в современную PostgreSQL. Часть 2
Введение в современную PostgreSQL. Часть 2
 
computer project code ''payroll'' (based on datafile handling)
computer project code ''payroll'' (based on datafile handling)computer project code ''payroll'' (based on datafile handling)
computer project code ''payroll'' (based on datafile handling)
 
More than 12 More things about Oracle Database 12c
More than 12 More things about Oracle Database 12cMore than 12 More things about Oracle Database 12c
More than 12 More things about Oracle Database 12c
 
Oracle 12c Automatic Data Optimization (ADO) - ILM
Oracle 12c Automatic Data Optimization (ADO) - ILMOracle 12c Automatic Data Optimization (ADO) - ILM
Oracle 12c Automatic Data Optimization (ADO) - ILM
 
Writing efficient sql
Writing efficient sqlWriting efficient sql
Writing efficient sql
 
Raw system logs processing with hive
Raw system logs processing with hiveRaw system logs processing with hive
Raw system logs processing with hive
 
Know your SQL Server - DMVs
Know your SQL Server - DMVsKnow your SQL Server - DMVs
Know your SQL Server - DMVs
 
Sql queries
Sql queriesSql queries
Sql queries
 
Postgres performance for humans
Postgres performance for humansPostgres performance for humans
Postgres performance for humans
 
2013 Collaborate - OAUG - Presentation
2013 Collaborate - OAUG - Presentation2013 Collaborate - OAUG - Presentation
2013 Collaborate - OAUG - Presentation
 
Database Development Replication Security Maintenance Report
Database Development Replication Security Maintenance ReportDatabase Development Replication Security Maintenance Report
Database Development Replication Security Maintenance Report
 
Oracle Diagnostics : Explain Plans (Simple)
Oracle Diagnostics : Explain Plans (Simple)Oracle Diagnostics : Explain Plans (Simple)
Oracle Diagnostics : Explain Plans (Simple)
 

Plus de Odoo

Plus de Odoo (20)

Timesheet Workshop: The Timesheet App People Love!
Timesheet Workshop: The Timesheet App People Love!Timesheet Workshop: The Timesheet App People Love!
Timesheet Workshop: The Timesheet App People Love!
 
Odoo 3D Product View with Google Model-Viewer
Odoo 3D Product View with Google Model-ViewerOdoo 3D Product View with Google Model-Viewer
Odoo 3D Product View with Google Model-Viewer
 
Keynote - Vision & Strategy
Keynote - Vision & StrategyKeynote - Vision & Strategy
Keynote - Vision & Strategy
 
Opening Keynote - Unveilling Odoo 14
Opening Keynote - Unveilling Odoo 14Opening Keynote - Unveilling Odoo 14
Opening Keynote - Unveilling Odoo 14
 
Extending Odoo with a Comprehensive Budgeting and Forecasting Capability
Extending Odoo with a Comprehensive Budgeting and Forecasting CapabilityExtending Odoo with a Comprehensive Budgeting and Forecasting Capability
Extending Odoo with a Comprehensive Budgeting and Forecasting Capability
 
Managing Multi-channel Selling with Odoo
Managing Multi-channel Selling with OdooManaging Multi-channel Selling with Odoo
Managing Multi-channel Selling with Odoo
 
Product Configurator: Advanced Use Case
Product Configurator: Advanced Use CaseProduct Configurator: Advanced Use Case
Product Configurator: Advanced Use Case
 
Accounting Automation: How Much Money We Saved and How?
Accounting Automation: How Much Money We Saved and How?Accounting Automation: How Much Money We Saved and How?
Accounting Automation: How Much Money We Saved and How?
 
Rock Your Logistics with Advanced Operations
Rock Your Logistics with Advanced OperationsRock Your Logistics with Advanced Operations
Rock Your Logistics with Advanced Operations
 
Transition from a cost to a flow-centric organization
Transition from a cost to a flow-centric organizationTransition from a cost to a flow-centric organization
Transition from a cost to a flow-centric organization
 
Synchronization: The Supply Chain Response to Overcome the Crisis
Synchronization: The Supply Chain Response to Overcome the CrisisSynchronization: The Supply Chain Response to Overcome the Crisis
Synchronization: The Supply Chain Response to Overcome the Crisis
 
Running a University with Odoo
Running a University with OdooRunning a University with Odoo
Running a University with Odoo
 
Down Payments on Purchase Orders in Odoo
Down Payments on Purchase Orders in OdooDown Payments on Purchase Orders in Odoo
Down Payments on Purchase Orders in Odoo
 
Odoo Implementation in Phases - Success Story of a Retail Chain 3Sach food
Odoo Implementation in Phases - Success Story of a Retail Chain 3Sach foodOdoo Implementation in Phases - Success Story of a Retail Chain 3Sach food
Odoo Implementation in Phases - Success Story of a Retail Chain 3Sach food
 
Migration from Salesforce to Odoo
Migration from Salesforce to OdooMigration from Salesforce to Odoo
Migration from Salesforce to Odoo
 
Preventing User Mistakes by Using Machine Learning
Preventing User Mistakes by Using Machine LearningPreventing User Mistakes by Using Machine Learning
Preventing User Mistakes by Using Machine Learning
 
Becoming an Odoo Expert: How to Prepare for the Certification
Becoming an Odoo Expert: How to Prepare for the Certification Becoming an Odoo Expert: How to Prepare for the Certification
Becoming an Odoo Expert: How to Prepare for the Certification
 
How Odoo helped an Organization Grow 3 Fold
How Odoo helped an Organization Grow 3 FoldHow Odoo helped an Organization Grow 3 Fold
How Odoo helped an Organization Grow 3 Fold
 
From Shopify to Odoo
From Shopify to OdooFrom Shopify to Odoo
From Shopify to Odoo
 
Digital Transformation at Old MacDonald Farms: A Personal Story
Digital Transformation at Old MacDonald Farms: A Personal StoryDigital Transformation at Old MacDonald Farms: A Personal Story
Digital Transformation at Old MacDonald Farms: A Personal Story
 

Dernier

obat aborsi bandung wa 081336238223 jual obat aborsi cytotec asli di bandung9...
obat aborsi bandung wa 081336238223 jual obat aborsi cytotec asli di bandung9...obat aborsi bandung wa 081336238223 jual obat aborsi cytotec asli di bandung9...
obat aborsi bandung wa 081336238223 jual obat aborsi cytotec asli di bandung9...
yulianti213969
 
Challenges and Opportunities: A Qualitative Study on Tax Compliance in Pakistan
Challenges and Opportunities: A Qualitative Study on Tax Compliance in PakistanChallenges and Opportunities: A Qualitative Study on Tax Compliance in Pakistan
Challenges and Opportunities: A Qualitative Study on Tax Compliance in Pakistan
vineshkumarsajnani12
 

Dernier (20)

Getting Real with AI - Columbus DAW - May 2024 - Nick Woo from AlignAI
Getting Real with AI - Columbus DAW - May 2024 - Nick Woo from AlignAIGetting Real with AI - Columbus DAW - May 2024 - Nick Woo from AlignAI
Getting Real with AI - Columbus DAW - May 2024 - Nick Woo from AlignAI
 
obat aborsi bandung wa 081336238223 jual obat aborsi cytotec asli di bandung9...
obat aborsi bandung wa 081336238223 jual obat aborsi cytotec asli di bandung9...obat aborsi bandung wa 081336238223 jual obat aborsi cytotec asli di bandung9...
obat aborsi bandung wa 081336238223 jual obat aborsi cytotec asli di bandung9...
 
UAE Bur Dubai Call Girls ☏ 0564401582 Call Girl in Bur Dubai
UAE Bur Dubai Call Girls ☏ 0564401582 Call Girl in Bur DubaiUAE Bur Dubai Call Girls ☏ 0564401582 Call Girl in Bur Dubai
UAE Bur Dubai Call Girls ☏ 0564401582 Call Girl in Bur Dubai
 
Challenges and Opportunities: A Qualitative Study on Tax Compliance in Pakistan
Challenges and Opportunities: A Qualitative Study on Tax Compliance in PakistanChallenges and Opportunities: A Qualitative Study on Tax Compliance in Pakistan
Challenges and Opportunities: A Qualitative Study on Tax Compliance in Pakistan
 
HomeRoots Pitch Deck | Investor Insights | April 2024
HomeRoots Pitch Deck | Investor Insights | April 2024HomeRoots Pitch Deck | Investor Insights | April 2024
HomeRoots Pitch Deck | Investor Insights | April 2024
 
Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1
 
Bangalore Call Girl Just Call♥️ 8084732287 ♥️Top Class Call Girl Service Avai...
Bangalore Call Girl Just Call♥️ 8084732287 ♥️Top Class Call Girl Service Avai...Bangalore Call Girl Just Call♥️ 8084732287 ♥️Top Class Call Girl Service Avai...
Bangalore Call Girl Just Call♥️ 8084732287 ♥️Top Class Call Girl Service Avai...
 
Paradip CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Paradip CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGParadip CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Paradip CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
 
Only Cash On Delivery Call Girls In Sikandarpur Gurgaon ❤️8448577510 ⊹Escorts...
Only Cash On Delivery Call Girls In Sikandarpur Gurgaon ❤️8448577510 ⊹Escorts...Only Cash On Delivery Call Girls In Sikandarpur Gurgaon ❤️8448577510 ⊹Escorts...
Only Cash On Delivery Call Girls In Sikandarpur Gurgaon ❤️8448577510 ⊹Escorts...
 
Berhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGBerhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
 
Escorts in Nungambakkam Phone 8250092165 Enjoy 24/7 Escort Service Enjoy Your...
Escorts in Nungambakkam Phone 8250092165 Enjoy 24/7 Escort Service Enjoy Your...Escorts in Nungambakkam Phone 8250092165 Enjoy 24/7 Escort Service Enjoy Your...
Escorts in Nungambakkam Phone 8250092165 Enjoy 24/7 Escort Service Enjoy Your...
 
Nashik Call Girl Just Call 7091819311 Top Class Call Girl Service Available
Nashik Call Girl Just Call 7091819311 Top Class Call Girl Service AvailableNashik Call Girl Just Call 7091819311 Top Class Call Girl Service Available
Nashik Call Girl Just Call 7091819311 Top Class Call Girl Service Available
 
Berhampur Call Girl Just Call 8084732287 Top Class Call Girl Service Available
Berhampur Call Girl Just Call 8084732287 Top Class Call Girl Service AvailableBerhampur Call Girl Just Call 8084732287 Top Class Call Girl Service Available
Berhampur Call Girl Just Call 8084732287 Top Class Call Girl Service Available
 
Uneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration PresentationUneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration Presentation
 
Lucknow Housewife Escorts by Sexy Bhabhi Service 8250092165
Lucknow Housewife Escorts  by Sexy Bhabhi Service 8250092165Lucknow Housewife Escorts  by Sexy Bhabhi Service 8250092165
Lucknow Housewife Escorts by Sexy Bhabhi Service 8250092165
 
Falcon Invoice Discounting: Empowering Your Business Growth
Falcon Invoice Discounting: Empowering Your Business GrowthFalcon Invoice Discounting: Empowering Your Business Growth
Falcon Invoice Discounting: Empowering Your Business Growth
 
Nanded Call Girl Just Call 8084732287 Top Class Call Girl Service Available
Nanded Call Girl Just Call 8084732287 Top Class Call Girl Service AvailableNanded Call Girl Just Call 8084732287 Top Class Call Girl Service Available
Nanded Call Girl Just Call 8084732287 Top Class Call Girl Service Available
 
Phases of Negotiation .pptx
 Phases of Negotiation .pptx Phases of Negotiation .pptx
Phases of Negotiation .pptx
 
Cannabis Legalization World Map: 2024 Updated
Cannabis Legalization World Map: 2024 UpdatedCannabis Legalization World Map: 2024 Updated
Cannabis Legalization World Map: 2024 Updated
 
PHX May 2024 Corporate Presentation Final
PHX May 2024 Corporate Presentation FinalPHX May 2024 Corporate Presentation Final
PHX May 2024 Corporate Presentation Final
 

Common Performance Pitfalls in Odoo apps

  • 1.
  • 2. Measuring is key. We need facts to ensure we’ve improved the system.
  • 4. Odoo logs Easiest starting point "POST /mail/init_messaging HTTP/1.0" 200 - 129 0.542 0.952 Last 3 figures are: ● Number of SQL queries ● Time spent on SQL queries ● Time spent on method excluding sql
  • 5. Odoo profiling method ● Built in profiler from odoo.tools.misc import profile from datetime import datetime [...] @profile("/tmp/profile_my_method%s.cprof" % datetime.now().isoformat()) def my_method(self): [...] ● Open result in snakeviz
  • 6.
  • 7. Other profiling methods: ● pyFlame ● pySpy And now the SQL side.
  • 8. log_destination = 'csvlog' logging_collector = on log_directory = '/var/log/postgresql/pg_log/' log_filename = 'postgresql-%Y-%m- %d_%H%M%S.log' log_min_duration_statement = 0 log_line_prefix = '%t [%p-%l] %q%u@%d ' lc_messages = 'en_US.UTF-8' And analyse with pgbadger ➔ Require postgresql config access ➔ Choose level with log_min_duration_statement ➔ HTML report as output ➔ Time consuming queries ◆ Per execution ◆ Due to the number of executions Log with PostgreSQL
  • 9.
  • 10. Most Odoo SQL queries were simple SELECT id FROM module_table WHERE search_domain AND record_rules ORDER BY order_by; SELECT field FROM module_table WHERE id=ANY([...]); UPDATE module_table SET field=value WHERE id IN ([...]); ➔ How is self.search([(‘field1_id.field2_ids.name’, ‘=’, ‘whatever’)]) evaluated? ◆ 13.0 VS 14.0 ◆ https://github.com/odoo/odoo/pull/52403 ◆ JOIN ➔ SELECT id with criterias ➔ SELECT field WHERE id
  • 11. Optimise SQL Query Need to know how PostgreSQL executes the query explain analyse SELECT sequence_prefix FROM account_move WHERE journal_id = 140 AND name != '/' AND date_trunc('year', date) = date_trunc('year', '2017-10-16'::date) AND id != 1129331 ORDER BY id DESC; ● Explain ● Explain (analyse/analyze, buffers, format=json) QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Index Scan using account_move_sequence_index2 on account_move (cost=0.42..94250.51 rows=550 width=12) (actual time=58.451..59.917 rows=1494 loops=1) Index Cond: (journal_id = 140) Filter: (((name)::text <> '/'::text) AND (id <> 1129331) AND (date_trunc('year'::text, (date)::timestamp with time zone) = date_trunc('year'::text, ('2017-10-16'::date)::timestamp with time zone))) Rows Removed by Filter: 110010 Planning time: 0.920 ms Execution time: 59.973 ms (6 rows)
  • 12.
  • 13.
  • 14. explain analyse SELECT sequence_prefix FROM account_move WHERE journal_id = 140 AND name != '/' AND date_trunc('year', date) = date_trunc('year', '2017-10-16'::date) AND id != 1129331 ORDER BY id DESC; CREATE INDEX ON account_move( journal_id, date_trunc('year'::text, date::timestamp with time zone), id DESC ) WHERE name::text <> '/'::text; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Index Scan using account_move_sequence_index2 on account_move (cost=0.42..94250.51 rows=550 width=12) (actual time=58.451..59.917 rows=1494 loops=1) Index Cond: (journal_id = 140) Filter: (((name)::text <> '/'::text) AND (id <> 1129331) AND (date_trunc('year'::text, (date)::timestamp with time zone) = date_trunc('year'::text, ('2017-10-16'::date)::timestamp with time zone))) Rows Removed by Filter: 110010 Planning time: 0.920 ms Execution time: 59.973 ms (6 rows) ERROR: functions in index expression must be marked IMMUTABLE
  • 15. explain analyse SELECT sequence_prefix FROM account_move WHERE journal_id = 140 AND name != '/' AND date_trunc('year', date) = date_trunc('year', '2017-10-16'::date) AND id != 1129331 ORDER BY id DESC; VS explain analyse SELECT sequence_prefix FROM account_move WHERE journal_id = 140 AND name != '/' AND date_trunc('year', date::timestamp without time zone) = date_trunc('year', '2017-10-16'::date) AND id != 1129331 ORDER BY id DESC; Execution time: 4.777 ms VS explain analyse SELECT sequence_prefix FROM account_move WHERE journal_id = 140 AND name != '/' AND date_trunc('year', date::timestamp without time zone) = date_trunc('year', '2017-10-16'::date) AND id != 1129331 ORDER BY id DESC LIMIT 1; Execution time: 49.815 ms
  • 16. # create index on account_move(journal_id, date_trunc('year'::text, date::timestamp without time zone)) WHERE name::text <> '/'::text; CREATE INDEX # explain analyse SELECT sequence_prefix FROM account_move WHERE journal_id = 140 AND name != '/' AND date_trunc('year', date::timestamp without time zone) = date_trunc('year', '2017-10-16'::date) AND id != 1129331 ORDER BY id DESC; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Sort (cost=570.59..571.94 rows=538 width=12) (actual time=3.479..3.520 rows=1494 loops=1) Sort Key: id DESC Sort Method: quicksort Memory: 165kB -> Index Scan using account_move_journal_id_date_trunc_idx on account_move (cost=0.43..546.19 rows=538 width=12) (actual time=0.179..2.841 rows=1494 loops=1) Index Cond: ((journal_id = 140) AND (date_trunc('year'::text, (date)::timestamp without time zone) = date_trunc('year'::text, ('2017-10-16'::date)::timestamp with time zone))) Filter: (id <> 1129331) Planning time: 1.048 ms Execution time: 3.620 ms (8 rows) # explain analyse SELECT sequence_prefix FROM account_move WHERE journal_id = 140 AND name != '/' AND date_trunc('year', date::timestamp without time zone) = date_trunc('year', '2017-10-16'::date) AND id != 1129331 ORDER BY id DESC limit 1; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Limit (cost=0.42..172.74 rows=1 width=12) (actual time=42.422..42.423 rows=1 loops=1) -> Index Scan using account_move_sequence_index2 on account_move (cost=0.42..92705.85 rows=538 width=12) (actual time=42.421..42.421 rows=1 loops=1) Index Cond: (journal_id = 140) Filter: (((name)::text <> '/'::text) AND (id <> 1129331) AND (date_trunc('year'::text, (date)::timestamp without time zone) = date_trunc('year'::text, ('2017-10- 16'::date)::timestamp with time zone))) Rows Removed by Filter: 109954 Planning time: 0.263 ms Execution time: 42.443 ms (7 rows) Beware the “limit 1”
  • 17. SQL Constraints Faster than python ones. Harder to update.
  • 18. Update once per transaction # timing Timing is on. # begin; BEGIN Time: 0.147 ms # update account_move set name='nse' where id=6; UPDATE 1 Time: 2.696 ms # update account_move set name='nse' where id=6; UPDATE 1 Time: 377.396 ms # timing Timing is on. # update account_move set name='nse' where id=6; UPDATE 1 Time: 2.656 ms # update account_move set name='nse' where id=6; UPDATE 1 Time: 2.621 ms .flush() !
  • 20. Compute Stored and not Stored fields in the same method.

Notes de l'éditeur

  1. Odoo logo centered w/ tagline
  2. Instead of the usual quote “you cannot improve what you cannot measure” Know what to improve. “It’s slow” may vary from people to people. Improving a piece of software without degrading other ones. Odoo provide tools out of the box to achieve this. External softwares will be used during this talk.
  3. Deploy Odoo Deploy Munin Configure PostgreSQL Improve PostgreSQL Which kind of index to use in PostgreSQL As well as other people talks regarding ORM, performance, ...
  4. Works out of the box! Add extra overhead! Alot! -> not in prod On Odoo.sh? Just _inherit your model, the method, decorate the method, and… that’s it!
  5. Place your own screenshot Select screenshot Click ‘Replace Image’ Select ‘Upload from computer’ from dropdown menu Choose photo Adjust accordingly, without distorting (stretching) photo
  6. Watch the RCO talks for python code optimisation
  7. Can do it using odoo but easier to analyse with Postgresql (thanks to pgbadger)
  8. Place your own screenshot Select screenshot Click ‘Replace Image’ Select ‘Upload from computer’ from dropdown menu Choose photo Adjust accordingly, without distorting (stretching) photo
  9. Place your own screenshot Select screenshot Click ‘Replace Image’ Select ‘Upload from computer’ from dropdown menu Choose photo Adjust accordingly, without distorting (stretching) photo
  10. Computing a stored field based on a non-stored one is equivalent
  11. Computing a stored field based on a non-stored one is equivalent