SlideShare a Scribd company logo
1 of 22
24 ottobre 2013.openerp.it

XML-RPC vs Psycopg2

Dr. Piero Cecchi

OpenERP
Analisi Prestazionale
Python script
XML-RPC vs Psycopg2
24 ottobre 2013.openerpday.it

XML-RPC vs Psycopg2

Dr. Piero Cecchi

PROBLEMA REALE
In un database nella Tabella:
●

account_move
il Campo:

●

id_partner
Non è sempre presente

2
24 ottobre 2013.openerpday.it

XML-RPC vs Psycopg2

Dr. Piero Cecchi

TUTTI I MOVIMENTI SENZA PARTNER SONO ABBINATI AL
PRIMO ID_PARTNER DELLA TABELLA account_move_line

3
24 ottobre 2013.openerpday.it

XML-RPC vs Psycopg2

Dr. Piero Cecchi

TABELLA account_move_line

4
24 ottobre 2013.openerpday.it

XML-RPC vs Psycopg2

Dr. Piero Cecchi

SCRITTO PROGRAMMA IN PYTHON E XML-RPC
….......
# SEARCH ID ACCOUNT MOVE LINE
args = [('state', '=', 'valid')]
ids = sock.execute(dbname, uid, pwd, 'account.move.line', 'search', args)
splitids=str(ids).split(',')
print splitids
rowcount=1
for row in splitids:
if rowcount == len(ids):
idmove = int(row[1:-1])
else:
idmove=int(row[1:])
print idmove
fields = ['partner_id','move_id'] #fields to read
data = sock.execute(dbname, uid, pwd, 'account.move.line', 'read',idmove, fields)
splitdata = str(data).split(',')
if splitdata[0][15:] <> 'False':
idpartner = int(splitdata[0][16:])
print data
…................................esempio read xml-rpc
{'partner_id': [231, 'Sguasxxxx Licia'], 'id': 19, 'move_id': [10, 'BNK2/2013/0004']}

5
24 ottobre 2013.openerpday.it

XML-RPC vs Psycopg2

Dr. Piero Cecchi

TABELLA account_move CORRETTAMENTE ABBINATA

6
24 ottobre 2013.openerpday.it

XML-RPC vs Psycopg2

Dr. Piero Cecchi

XML-RPC TIME: 3.27

7
24 ottobre 2013.openerpday.it

XML-RPC vs Psycopg2

Dr. Piero Cecchi

SCRITTO PROGRAMMA IN PYTHON E PSYCOPG2
…......
c_line.execute("SELECT move_id, partner_id, credit, debit FROM
account_move_line WHERE (partner_id > 0) ORDER by partner_id")
c_line.execute("SELECT DISTINCT move_id, partner_id FROM account_move_line
ORDER by partner_id")
row_count = 0
for row in c_line:
row_count += 1
update_line="UPDATE account_move SET partner_id=%s where id=%s"
try:
c_move.execute(update_line,(row[1],row[0],))
print update_line
print "Cursor_row:%s - Partner_id:%s - Move_id:%s" %(row_count, row[1],
row[0],)
except psycopg2.DatabaseError, e:
print e.pgcode
print e.pgerror
sys.exit()
c_move.execute("COMMIT")

8
24 ottobre 2013.openerpday.it

XML-RPC vs Psycopg2

Dr. Piero Cecchi

BASIC MODULE USAGE - PSYCOPG2
>>> import psycopg2
# Connect to an existing database
>>> conn = psycopg2.connect("dbname=test user=postgres")
# Open a cursor to perform database operations
>>> cur = conn.cursor()
# Execute a command: this creates a new table
>>> cur.execute("CREATE TABLE test (id serial PRIMARY KEY, num integer, data varchar);")
# Pass data to fill a query placeholders and let Psycopg perform
# the correct conversion (no more SQL injections!)
>>> cur.execute("INSERT INTO test (num, data) VALUES (%s, %s)",
...
(100, "abc'def"))
# Query the database and obtain data as Python objects
>>> cur.execute("SELECT * FROM test;")
>>> cur.fetchone()
(1, 100, "abc'def")
# Make the changes to the database persistent
>>> conn.commit()
# Close communication with the database
>>> cur.close()
>>> conn.close()
9
24 ottobre 2013.openerpday.it

XML-RPC vs Psycopg2

Dr. Piero Cecchi

DATABASE ERROR TEST- PSYCOPG2
#!/usr/bin/python
# Replace <USERNAME_DATABASE>, <USERNAME>, and <PASSWORD> below with
your actual DB, user, and password.
import psycopg2
import sys
con = None
try:
con = psycopg2.connect(database='<USERNAME_DATABASE>', user='<USERNAME>',
password='<PASSWORD>')
cur = con.cursor()
cur.execute("SELECT * FROM testschema.testtable")1
rows = cur.fetchall()
for row in rows:
print row
except psycopg2.DatabaseError, e:
print 'Error %s' % e
sys.exit(1)
finally:
if con:
con.close()
10
24 ottobre 2013.openerpday.it

XML-RPC vs Psycopg2

Dr. Piero Cecchi

SELECT PSYCOPG2 - TIME: 0.25

11
24 ottobre 2013.openerpday.it

XML-RPC vs Psycopg2

Dr. Piero Cecchi

SELECT DISTINCT PSYCOPG2 - TIME: 0.06

12
24 ottobre 2013.openerpday.it

XML-RPC vs Psycopg2

Dr. Piero Cecchi

SQL EXISTS - UPDATE EXAMPLE
UPDATE suppliers
SET supplier_name = (select customers.name
from customers
where customers.customer_id = suppliers.supplier_id)
WHERE EXISTS (select customers.name
from customers
where customers.customer_id = suppliers.supplier_id);

13
24 ottobre 2013.openerpday.it

XML-RPC vs Psycopg2

Dr. Piero Cecchi

SCRITTO PROGRAMMA IN PYTHON E SQL EXISTS
…......
try:
conn = psycopg2.connect(conn_string)
# print the connection string we will use to connect
print "Connecting to databasen->%s" % (conn_string)
cur = conn.cursor()
update_set = "UPDATE account_move SET partner_id = "
update_select = "(SELECT DISTINCT partner_id FROM account_move_line
WHERE account_move.id = account_move_line.move_id)"
cur.execute(update_set + update_select + " WHERE EXISTS " +update_select)
cur.execute("COMMIT")
cur.close()
conn.close()
except psycopg2.DatabaseError, e:
print e.pgcode
print e.pgerror
sys.exit()

14
24 ottobre 2013.openerpday.it

XML-RPC vs Psycopg2

Dr. Piero Cecchi

SQL EXISTS PSYCOPG2 – TIME 0.02

15
24 ottobre 2013.openerpday.it

XML-RPC vs Psycopg2

Dr. Piero Cecchi

SCRIPT PSQL E SQL EXISTS
T="$(date +%s)"
psql -U demo -d acsi7demo -c "UPDATE account_move SET partner_id =
(SELECT DISTINCT partner_id FROM account_move_line
WHERE account_move.id = account_move_line.move_id)
WHERE EXISTS (SELECT DISTINCT partner_id FROM account_move_line
WHERE account_move.id = account_move_line.move_id)"
T="$(($(date +%s)-T))"
echo $T

16
24 ottobre 2013.openerpday.it

XML-RPC vs Psycopg2

Dr. Piero Cecchi

SCRIPT PSQL E SQL EXISTS TIME: 0

17
24 ottobre 2013.openerpday.it

XML-RPC vs Psycopg2

Dr. Piero Cecchi

PSQL E SQL EXISTS TIME: 0,034

18
24 ottobre 2013.openerpday.it

XML-RPC vs Psycopg2

Dr. Piero Cecchi

ANALISI PRESTAZIONALE

19
24 ottobre 2013.openerpday.it

XML-RPC vs Psycopg2

Dr. Piero Cecchi

XML-RPC VS PSYCOPG2
XML-RPC VANTAGGI:

PSYCOPG2 VANTAGGI:

●

SICUREZZA

●

VELOCITA'

●

CONTROLLO ORM OPENERP

●

UTILIZZO SQL STANDARD

●

UTILIZZO “Etichette” CAMPI

●

PORTABILITA' QUERY

20
24 ottobre 2013.openerpday.it

XML-RPC vs Psycopg2

Dr. Piero Cecchi

RINGRAZIAMENTI
Associazione OpenERP Italia
http://www.openerp-italia.org
2013.openerpday.it
Italian PostgreSQL Users Group
http://www.itpug.org
2013.pgday.it

21
24 ottobre 2013.openerpday.it

XML-RPC vs Psycopg2

Dr. Piero Cecchi

Q&A
CONTATTI
piero.cecchi@gmail.com
software@cecchi.com
https://github.com/cecchip/openerpday2013.git

22

More Related Content

What's hot

Maximizing SQL Reviews and Tuning with pt-query-digest
Maximizing SQL Reviews and Tuning with pt-query-digestMaximizing SQL Reviews and Tuning with pt-query-digest
Maximizing SQL Reviews and Tuning with pt-query-digestPythian
 
React Back to the Future
React Back to the FutureReact Back to the Future
React Back to the Future500Tech
 
ESNext for humans - LvivJS 16 August 2014
ESNext for humans - LvivJS 16 August 2014ESNext for humans - LvivJS 16 August 2014
ESNext for humans - LvivJS 16 August 2014Jan Jongboom
 
VPN Access Runbook
VPN Access RunbookVPN Access Runbook
VPN Access RunbookTaha Shakeel
 
Ensure code quality with vs2012
Ensure code quality with vs2012Ensure code quality with vs2012
Ensure code quality with vs2012Sandeep Joshi
 
Form認証で学ぶSpring Security入門
Form認証で学ぶSpring Security入門Form認証で学ぶSpring Security入門
Form認証で学ぶSpring Security入門Ryosuke Uchitate
 
Tomcat连接池配置方法V2.1
Tomcat连接池配置方法V2.1Tomcat连接池配置方法V2.1
Tomcat连接池配置方法V2.1Zianed Hou
 
Wicket Security Presentation
Wicket Security PresentationWicket Security Presentation
Wicket Security Presentationmrmean
 
code for quiz in my sql
code for quiz  in my sql code for quiz  in my sql
code for quiz in my sql JOYITAKUNDU1
 
VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEVISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEDarwin Durand
 
Pymongo for the Clueless
Pymongo for the CluelessPymongo for the Clueless
Pymongo for the CluelessChee Leong Chow
 
The redux saga begins
The redux saga beginsThe redux saga begins
The redux saga beginsDaniel Franz
 
Java practice programs for beginners
Java practice programs for beginnersJava practice programs for beginners
Java practice programs for beginnersishan0019
 
Seven deadly smells of Automated Tests
Seven deadly smells of Automated TestsSeven deadly smells of Automated Tests
Seven deadly smells of Automated Testsowennell
 
Java 8 - Nuts and Bold - SFEIR Benelux
Java 8 - Nuts and Bold - SFEIR BeneluxJava 8 - Nuts and Bold - SFEIR Benelux
Java 8 - Nuts and Bold - SFEIR Beneluxyohanbeschi
 

What's hot (18)

Maximizing SQL Reviews and Tuning with pt-query-digest
Maximizing SQL Reviews and Tuning with pt-query-digestMaximizing SQL Reviews and Tuning with pt-query-digest
Maximizing SQL Reviews and Tuning with pt-query-digest
 
React Back to the Future
React Back to the FutureReact Back to the Future
React Back to the Future
 
Clojure functions midje
Clojure functions midjeClojure functions midje
Clojure functions midje
 
ESNext for humans - LvivJS 16 August 2014
ESNext for humans - LvivJS 16 August 2014ESNext for humans - LvivJS 16 August 2014
ESNext for humans - LvivJS 16 August 2014
 
VPN Access Runbook
VPN Access RunbookVPN Access Runbook
VPN Access Runbook
 
Ensure code quality with vs2012
Ensure code quality with vs2012Ensure code quality with vs2012
Ensure code quality with vs2012
 
Form認証で学ぶSpring Security入門
Form認証で学ぶSpring Security入門Form認証で学ぶSpring Security入門
Form認証で学ぶSpring Security入門
 
Tomcat连接池配置方法V2.1
Tomcat连接池配置方法V2.1Tomcat连接池配置方法V2.1
Tomcat连接池配置方法V2.1
 
Wicket Security Presentation
Wicket Security PresentationWicket Security Presentation
Wicket Security Presentation
 
code for quiz in my sql
code for quiz  in my sql code for quiz  in my sql
code for quiz in my sql
 
VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEVISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLE
 
Ip project visual mobile
Ip project visual mobileIp project visual mobile
Ip project visual mobile
 
Pymongo for the Clueless
Pymongo for the CluelessPymongo for the Clueless
Pymongo for the Clueless
 
The redux saga begins
The redux saga beginsThe redux saga begins
The redux saga begins
 
Java practice programs for beginners
Java practice programs for beginnersJava practice programs for beginners
Java practice programs for beginners
 
Seven deadly smells of Automated Tests
Seven deadly smells of Automated TestsSeven deadly smells of Automated Tests
Seven deadly smells of Automated Tests
 
Java 8 - Nuts and Bold - SFEIR Benelux
Java 8 - Nuts and Bold - SFEIR BeneluxJava 8 - Nuts and Bold - SFEIR Benelux
Java 8 - Nuts and Bold - SFEIR Benelux
 
Easy Button
Easy ButtonEasy Button
Easy Button
 

Viewers also liked (11)

OpenERP 7.0 - Sviluppo Moduli
OpenERP 7.0 - Sviluppo ModuliOpenERP 7.0 - Sviluppo Moduli
OpenERP 7.0 - Sviluppo Moduli
 
01 CRM e Social media marketing intelligence con Odoo
01 CRM e Social media marketing intelligence con Odoo01 CRM e Social media marketing intelligence con Odoo
01 CRM e Social media marketing intelligence con Odoo
 
17 Quickorder e YAPOS - yet another pos
17 Quickorder e YAPOS - yet another pos17 Quickorder e YAPOS - yet another pos
17 Quickorder e YAPOS - yet another pos
 
05 OCA, da Oggi Contribuisco Anch'io!
05 OCA, da Oggi Contribuisco Anch'io!05 OCA, da Oggi Contribuisco Anch'io!
05 OCA, da Oggi Contribuisco Anch'io!
 
11 Riconciliazione bancaria
11 Riconciliazione bancaria11 Riconciliazione bancaria
11 Riconciliazione bancaria
 
13 Open ERP Italia Network
13 Open ERP Italia Network13 Open ERP Italia Network
13 Open ERP Italia Network
 
08 Fatturazione Elettronica P.A. con Odoo
08 Fatturazione Elettronica P.A. con Odoo08 Fatturazione Elettronica P.A. con Odoo
08 Fatturazione Elettronica P.A. con Odoo
 
09 API V8 for Dummies
09 API V8 for Dummies09 API V8 for Dummies
09 API V8 for Dummies
 
16 ​Odoo e test automatici
16 ​Odoo e test automatici16 ​Odoo e test automatici
16 ​Odoo e test automatici
 
15 Odoo come sistema di ticketing ed helpdesk avanzato​
15 Odoo come sistema di ticketing ed helpdesk avanzato​15 Odoo come sistema di ticketing ed helpdesk avanzato​
15 Odoo come sistema di ticketing ed helpdesk avanzato​
 
201607 03 - odoo 8.0
201607 03 - odoo 8.0201607 03 - odoo 8.0
201607 03 - odoo 8.0
 

Similar to XML-RPC vs Psycopg2 Performance Analysis

Running Intelligent Applications inside a Database: Deep Learning with Python...
Running Intelligent Applications inside a Database: Deep Learning with Python...Running Intelligent Applications inside a Database: Deep Learning with Python...
Running Intelligent Applications inside a Database: Deep Learning with Python...Miguel González-Fierro
 
Programming with Python and PostgreSQL
Programming with Python and PostgreSQLProgramming with Python and PostgreSQL
Programming with Python and PostgreSQLPeter Eisentraut
 
Psycopg2 - Connect to PostgreSQL using Python Script
Psycopg2 - Connect to PostgreSQL using Python ScriptPsycopg2 - Connect to PostgreSQL using Python Script
Psycopg2 - Connect to PostgreSQL using Python ScriptSurvey Department
 
Adding replication protocol support for psycopg2
Adding replication protocol support for psycopg2Adding replication protocol support for psycopg2
Adding replication protocol support for psycopg2Alexander Shulgin
 
Numerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learnNumerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learnArnaud Joly
 
Advanced Postgres Monitoring
Advanced Postgres MonitoringAdvanced Postgres Monitoring
Advanced Postgres MonitoringDenish Patel
 
Robert Pankowecki - Czy sprzedawcy SQLowych baz nas oszukali?
Robert Pankowecki - Czy sprzedawcy SQLowych baz nas oszukali?Robert Pankowecki - Czy sprzedawcy SQLowych baz nas oszukali?
Robert Pankowecki - Czy sprzedawcy SQLowych baz nas oszukali?SegFaultConf
 
Agile Data Science 2.0
Agile Data Science 2.0Agile Data Science 2.0
Agile Data Science 2.0Russell Jurney
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manualsameer farooq
 
Agile Data Science 2.0 - Big Data Science Meetup
Agile Data Science 2.0 - Big Data Science MeetupAgile Data Science 2.0 - Big Data Science Meetup
Agile Data Science 2.0 - Big Data Science MeetupRussell Jurney
 
Python na Infraestrutura 
MySQL do Facebook

Python na Infraestrutura 
MySQL do Facebook
Python na Infraestrutura 
MySQL do Facebook

Python na Infraestrutura 
MySQL do Facebook
Artur Rodrigues
 
Agile Data Science 2.0
Agile Data Science 2.0Agile Data Science 2.0
Agile Data Science 2.0Russell Jurney
 
Connecting and using PostgreSQL database with psycopg2 [Python 2.7]
Connecting and using PostgreSQL database with psycopg2 [Python 2.7]Connecting and using PostgreSQL database with psycopg2 [Python 2.7]
Connecting and using PostgreSQL database with psycopg2 [Python 2.7]Dinesh Neupane
 
How to fully automate a store.pptx
How to fully automate a store.pptxHow to fully automate a store.pptx
How to fully automate a store.pptxIgor Moiseev
 
Relational Database Access with Python ‘sans’ ORM
Relational Database Access with Python ‘sans’ ORM  Relational Database Access with Python ‘sans’ ORM
Relational Database Access with Python ‘sans’ ORM Mark Rees
 

Similar to XML-RPC vs Psycopg2 Performance Analysis (20)

Running Intelligent Applications inside a Database: Deep Learning with Python...
Running Intelligent Applications inside a Database: Deep Learning with Python...Running Intelligent Applications inside a Database: Deep Learning with Python...
Running Intelligent Applications inside a Database: Deep Learning with Python...
 
Programming with Python and PostgreSQL
Programming with Python and PostgreSQLProgramming with Python and PostgreSQL
Programming with Python and PostgreSQL
 
Psycopg2 - Connect to PostgreSQL using Python Script
Psycopg2 - Connect to PostgreSQL using Python ScriptPsycopg2 - Connect to PostgreSQL using Python Script
Psycopg2 - Connect to PostgreSQL using Python Script
 
Adding replication protocol support for psycopg2
Adding replication protocol support for psycopg2Adding replication protocol support for psycopg2
Adding replication protocol support for psycopg2
 
Noinject
NoinjectNoinject
Noinject
 
Database connectivity in python
Database connectivity in pythonDatabase connectivity in python
Database connectivity in python
 
Numerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learnNumerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learn
 
Advanced Postgres Monitoring
Advanced Postgres MonitoringAdvanced Postgres Monitoring
Advanced Postgres Monitoring
 
Robert Pankowecki - Czy sprzedawcy SQLowych baz nas oszukali?
Robert Pankowecki - Czy sprzedawcy SQLowych baz nas oszukali?Robert Pankowecki - Czy sprzedawcy SQLowych baz nas oszukali?
Robert Pankowecki - Czy sprzedawcy SQLowych baz nas oszukali?
 
Python database connection
Python database connectionPython database connection
Python database connection
 
Agile Data Science 2.0
Agile Data Science 2.0Agile Data Science 2.0
Agile Data Science 2.0
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
 
Agile Data Science 2.0 - Big Data Science Meetup
Agile Data Science 2.0 - Big Data Science MeetupAgile Data Science 2.0 - Big Data Science Meetup
Agile Data Science 2.0 - Big Data Science Meetup
 
Agile Data Science
Agile Data ScienceAgile Data Science
Agile Data Science
 
Python na Infraestrutura 
MySQL do Facebook

Python na Infraestrutura 
MySQL do Facebook
Python na Infraestrutura 
MySQL do Facebook

Python na Infraestrutura 
MySQL do Facebook

 
Agile Data Science 2.0
Agile Data Science 2.0Agile Data Science 2.0
Agile Data Science 2.0
 
Python lecture 03
Python lecture 03Python lecture 03
Python lecture 03
 
Connecting and using PostgreSQL database with psycopg2 [Python 2.7]
Connecting and using PostgreSQL database with psycopg2 [Python 2.7]Connecting and using PostgreSQL database with psycopg2 [Python 2.7]
Connecting and using PostgreSQL database with psycopg2 [Python 2.7]
 
How to fully automate a store.pptx
How to fully automate a store.pptxHow to fully automate a store.pptx
How to fully automate a store.pptx
 
Relational Database Access with Python ‘sans’ ORM
Relational Database Access with Python ‘sans’ ORM  Relational Database Access with Python ‘sans’ ORM
Relational Database Access with Python ‘sans’ ORM
 

More from Associazione Odoo Italia

14 Il borsino: un nuovo modo di gestire il flusso di acquisto
14 Il borsino: un nuovo modo di gestire il flusso di acquisto14 Il borsino: un nuovo modo di gestire il flusso di acquisto
14 Il borsino: un nuovo modo di gestire il flusso di acquistoAssociazione Odoo Italia
 
07 Fatturazione Elettronica (PA) e Conservazione Sostitutiva
07 Fatturazione Elettronica (PA) e Conservazione Sostitutiva07 Fatturazione Elettronica (PA) e Conservazione Sostitutiva
07 Fatturazione Elettronica (PA) e Conservazione SostitutivaAssociazione Odoo Italia
 
04 OdooPLM per organizzare la documentazione tecnica di tutta l'azienda
04 OdooPLM per organizzare la documentazione tecnica di tutta l'azienda04 OdooPLM per organizzare la documentazione tecnica di tutta l'azienda
04 OdooPLM per organizzare la documentazione tecnica di tutta l'aziendaAssociazione Odoo Italia
 
03 Estensione delle proprietà di Odoo per la generazione di preventivi complessi
03 Estensione delle proprietà di Odoo per la generazione di preventivi complessi03 Estensione delle proprietà di Odoo per la generazione di preventivi complessi
03 Estensione delle proprietà di Odoo per la generazione di preventivi complessiAssociazione Odoo Italia
 

More from Associazione Odoo Italia (19)

Le licenze software ed affini
Le licenze software ed affiniLe licenze software ed affini
Le licenze software ed affini
 
Gestione Magazzino con Odoo
Gestione Magazzino con OdooGestione Magazzino con Odoo
Gestione Magazzino con Odoo
 
14 Il borsino: un nuovo modo di gestire il flusso di acquisto
14 Il borsino: un nuovo modo di gestire il flusso di acquisto14 Il borsino: un nuovo modo di gestire il flusso di acquisto
14 Il borsino: un nuovo modo di gestire il flusso di acquisto
 
10 Gestione Cespiti​
10 Gestione Cespiti​10 Gestione Cespiti​
10 Gestione Cespiti​
 
07 Fatturazione Elettronica (PA) e Conservazione Sostitutiva
07 Fatturazione Elettronica (PA) e Conservazione Sostitutiva07 Fatturazione Elettronica (PA) e Conservazione Sostitutiva
07 Fatturazione Elettronica (PA) e Conservazione Sostitutiva
 
06 Odoo Community Association
06 Odoo Community Association06 Odoo Community Association
06 Odoo Community Association
 
04 OdooPLM per organizzare la documentazione tecnica di tutta l'azienda
04 OdooPLM per organizzare la documentazione tecnica di tutta l'azienda04 OdooPLM per organizzare la documentazione tecnica di tutta l'azienda
04 OdooPLM per organizzare la documentazione tecnica di tutta l'azienda
 
03 Estensione delle proprietà di Odoo per la generazione di preventivi complessi
03 Estensione delle proprietà di Odoo per la generazione di preventivi complessi03 Estensione delle proprietà di Odoo per la generazione di preventivi complessi
03 Estensione delle proprietà di Odoo per la generazione di preventivi complessi
 
02 Ritenuta d'acconto
02 Ritenuta d'acconto02 Ritenuta d'acconto
02 Ritenuta d'acconto
 
Reports e stampe con OpenERP
Reports e stampe con OpenERPReports e stampe con OpenERP
Reports e stampe con OpenERP
 
Import/Export di dati con OpenERP
Import/Export di dati con OpenERPImport/Export di dati con OpenERP
Import/Export di dati con OpenERP
 
Causali e Compensazioni Easy Way
Causali e Compensazioni Easy WayCausali e Compensazioni Easy Way
Causali e Compensazioni Easy Way
 
Sviluppare moduli per il client web
Sviluppare moduli per il client webSviluppare moduli per il client web
Sviluppare moduli per il client web
 
Distinta base a dimensioni variabili
Distinta base a dimensioni variabiliDistinta base a dimensioni variabili
Distinta base a dimensioni variabili
 
OpenERP Community Association
OpenERP Community AssociationOpenERP Community Association
OpenERP Community Association
 
OpenERP in Italia - tipico caso d'uso
OpenERP in Italia - tipico caso d'usoOpenERP in Italia - tipico caso d'uso
OpenERP in Italia - tipico caso d'uso
 
Launchpad e code review
Launchpad e code reviewLaunchpad e code review
Launchpad e code review
 
Contbilità: le novità
Contbilità: le novitàContbilità: le novità
Contbilità: le novità
 
Open erp vs sap
Open erp vs sapOpen erp vs sap
Open erp vs sap
 

XML-RPC vs Psycopg2 Performance Analysis

  • 1. 24 ottobre 2013.openerp.it XML-RPC vs Psycopg2 Dr. Piero Cecchi OpenERP Analisi Prestazionale Python script XML-RPC vs Psycopg2
  • 2. 24 ottobre 2013.openerpday.it XML-RPC vs Psycopg2 Dr. Piero Cecchi PROBLEMA REALE In un database nella Tabella: ● account_move il Campo: ● id_partner Non è sempre presente 2
  • 3. 24 ottobre 2013.openerpday.it XML-RPC vs Psycopg2 Dr. Piero Cecchi TUTTI I MOVIMENTI SENZA PARTNER SONO ABBINATI AL PRIMO ID_PARTNER DELLA TABELLA account_move_line 3
  • 4. 24 ottobre 2013.openerpday.it XML-RPC vs Psycopg2 Dr. Piero Cecchi TABELLA account_move_line 4
  • 5. 24 ottobre 2013.openerpday.it XML-RPC vs Psycopg2 Dr. Piero Cecchi SCRITTO PROGRAMMA IN PYTHON E XML-RPC …....... # SEARCH ID ACCOUNT MOVE LINE args = [('state', '=', 'valid')] ids = sock.execute(dbname, uid, pwd, 'account.move.line', 'search', args) splitids=str(ids).split(',') print splitids rowcount=1 for row in splitids: if rowcount == len(ids): idmove = int(row[1:-1]) else: idmove=int(row[1:]) print idmove fields = ['partner_id','move_id'] #fields to read data = sock.execute(dbname, uid, pwd, 'account.move.line', 'read',idmove, fields) splitdata = str(data).split(',') if splitdata[0][15:] <> 'False': idpartner = int(splitdata[0][16:]) print data …................................esempio read xml-rpc {'partner_id': [231, 'Sguasxxxx Licia'], 'id': 19, 'move_id': [10, 'BNK2/2013/0004']} 5
  • 6. 24 ottobre 2013.openerpday.it XML-RPC vs Psycopg2 Dr. Piero Cecchi TABELLA account_move CORRETTAMENTE ABBINATA 6
  • 7. 24 ottobre 2013.openerpday.it XML-RPC vs Psycopg2 Dr. Piero Cecchi XML-RPC TIME: 3.27 7
  • 8. 24 ottobre 2013.openerpday.it XML-RPC vs Psycopg2 Dr. Piero Cecchi SCRITTO PROGRAMMA IN PYTHON E PSYCOPG2 …...... c_line.execute("SELECT move_id, partner_id, credit, debit FROM account_move_line WHERE (partner_id > 0) ORDER by partner_id") c_line.execute("SELECT DISTINCT move_id, partner_id FROM account_move_line ORDER by partner_id") row_count = 0 for row in c_line: row_count += 1 update_line="UPDATE account_move SET partner_id=%s where id=%s" try: c_move.execute(update_line,(row[1],row[0],)) print update_line print "Cursor_row:%s - Partner_id:%s - Move_id:%s" %(row_count, row[1], row[0],) except psycopg2.DatabaseError, e: print e.pgcode print e.pgerror sys.exit() c_move.execute("COMMIT") 8
  • 9. 24 ottobre 2013.openerpday.it XML-RPC vs Psycopg2 Dr. Piero Cecchi BASIC MODULE USAGE - PSYCOPG2 >>> import psycopg2 # Connect to an existing database >>> conn = psycopg2.connect("dbname=test user=postgres") # Open a cursor to perform database operations >>> cur = conn.cursor() # Execute a command: this creates a new table >>> cur.execute("CREATE TABLE test (id serial PRIMARY KEY, num integer, data varchar);") # Pass data to fill a query placeholders and let Psycopg perform # the correct conversion (no more SQL injections!) >>> cur.execute("INSERT INTO test (num, data) VALUES (%s, %s)", ... (100, "abc'def")) # Query the database and obtain data as Python objects >>> cur.execute("SELECT * FROM test;") >>> cur.fetchone() (1, 100, "abc'def") # Make the changes to the database persistent >>> conn.commit() # Close communication with the database >>> cur.close() >>> conn.close() 9
  • 10. 24 ottobre 2013.openerpday.it XML-RPC vs Psycopg2 Dr. Piero Cecchi DATABASE ERROR TEST- PSYCOPG2 #!/usr/bin/python # Replace <USERNAME_DATABASE>, <USERNAME>, and <PASSWORD> below with your actual DB, user, and password. import psycopg2 import sys con = None try: con = psycopg2.connect(database='<USERNAME_DATABASE>', user='<USERNAME>', password='<PASSWORD>') cur = con.cursor() cur.execute("SELECT * FROM testschema.testtable")1 rows = cur.fetchall() for row in rows: print row except psycopg2.DatabaseError, e: print 'Error %s' % e sys.exit(1) finally: if con: con.close() 10
  • 11. 24 ottobre 2013.openerpday.it XML-RPC vs Psycopg2 Dr. Piero Cecchi SELECT PSYCOPG2 - TIME: 0.25 11
  • 12. 24 ottobre 2013.openerpday.it XML-RPC vs Psycopg2 Dr. Piero Cecchi SELECT DISTINCT PSYCOPG2 - TIME: 0.06 12
  • 13. 24 ottobre 2013.openerpday.it XML-RPC vs Psycopg2 Dr. Piero Cecchi SQL EXISTS - UPDATE EXAMPLE UPDATE suppliers SET supplier_name = (select customers.name from customers where customers.customer_id = suppliers.supplier_id) WHERE EXISTS (select customers.name from customers where customers.customer_id = suppliers.supplier_id); 13
  • 14. 24 ottobre 2013.openerpday.it XML-RPC vs Psycopg2 Dr. Piero Cecchi SCRITTO PROGRAMMA IN PYTHON E SQL EXISTS …...... try: conn = psycopg2.connect(conn_string) # print the connection string we will use to connect print "Connecting to databasen->%s" % (conn_string) cur = conn.cursor() update_set = "UPDATE account_move SET partner_id = " update_select = "(SELECT DISTINCT partner_id FROM account_move_line WHERE account_move.id = account_move_line.move_id)" cur.execute(update_set + update_select + " WHERE EXISTS " +update_select) cur.execute("COMMIT") cur.close() conn.close() except psycopg2.DatabaseError, e: print e.pgcode print e.pgerror sys.exit() 14
  • 15. 24 ottobre 2013.openerpday.it XML-RPC vs Psycopg2 Dr. Piero Cecchi SQL EXISTS PSYCOPG2 – TIME 0.02 15
  • 16. 24 ottobre 2013.openerpday.it XML-RPC vs Psycopg2 Dr. Piero Cecchi SCRIPT PSQL E SQL EXISTS T="$(date +%s)" psql -U demo -d acsi7demo -c "UPDATE account_move SET partner_id = (SELECT DISTINCT partner_id FROM account_move_line WHERE account_move.id = account_move_line.move_id) WHERE EXISTS (SELECT DISTINCT partner_id FROM account_move_line WHERE account_move.id = account_move_line.move_id)" T="$(($(date +%s)-T))" echo $T 16
  • 17. 24 ottobre 2013.openerpday.it XML-RPC vs Psycopg2 Dr. Piero Cecchi SCRIPT PSQL E SQL EXISTS TIME: 0 17
  • 18. 24 ottobre 2013.openerpday.it XML-RPC vs Psycopg2 Dr. Piero Cecchi PSQL E SQL EXISTS TIME: 0,034 18
  • 19. 24 ottobre 2013.openerpday.it XML-RPC vs Psycopg2 Dr. Piero Cecchi ANALISI PRESTAZIONALE 19
  • 20. 24 ottobre 2013.openerpday.it XML-RPC vs Psycopg2 Dr. Piero Cecchi XML-RPC VS PSYCOPG2 XML-RPC VANTAGGI: PSYCOPG2 VANTAGGI: ● SICUREZZA ● VELOCITA' ● CONTROLLO ORM OPENERP ● UTILIZZO SQL STANDARD ● UTILIZZO “Etichette” CAMPI ● PORTABILITA' QUERY 20
  • 21. 24 ottobre 2013.openerpday.it XML-RPC vs Psycopg2 Dr. Piero Cecchi RINGRAZIAMENTI Associazione OpenERP Italia http://www.openerp-italia.org 2013.openerpday.it Italian PostgreSQL Users Group http://www.itpug.org 2013.pgday.it 21
  • 22. 24 ottobre 2013.openerpday.it XML-RPC vs Psycopg2 Dr. Piero Cecchi Q&A CONTATTI piero.cecchi@gmail.com software@cecchi.com https://github.com/cecchip/openerpday2013.git 22