0.5 second connection overhead
See original GitHub issueI’m having some issues with my connection requests ever since I have followed the best practices defined in the docs:
Code in docs:
from flask import Flask
from peewee import *
database = SqliteDatabase('my_app.db')
app = Flask(__name__)
# This hook ensures that a connection is opened to handle any queries
# generated by the request.
@app.before_request
def _db_connect():
database.connect()
# This hook ensures that the connection is closed when we've finished
# processing the request.
@app.teardown_request
def _db_close(exc):
if not database.is_closed():
database.close()
After this change, all handled requests have a 0.5 second overhead in response time.
I’m currently investigating and was wondering if this was something that could be somehow caused by Peewee’s handling/closing of new connections, or if it is something else.
Thanks for your help.
Will
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (3 by maintainers)
Top Results From Across the Web
TCP Over IP Bandwidth Overhead - Packet Pushers
How long will it take to transfer a 100MB file over an IPSec tunnel running across a dedicated 100Mbps Ethernet link? 1 Second?...
Read more >Understanding network overhead - Catalin Dumitru
The other half is network latency and the overhead of actually establishing a connection with your servers. In this blog post we will ......
Read more >Connection Pooling - How much of an overhead is it?
A simple pool should be able to handle 100K allocations per second or more or about 10 micro-seconds. However, as soon as you...
Read more >CS 356 Flashcards - Cram.com
0.5 -Mbps - >= 125 packets per second ... Using a TCP SYN spoofing attacker, the attacker aims to flood the table of...
Read more >SSL Performance Overhead in MySQL - Percona
Test 2: Connection Time. For the second test, I wrote a simple Perl script to just connect and disconnect from the database as...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Your snippet is opening and closing a database connection at every request. There is an overhead time built into it (You can’t escape it). Maybe you should consider altering the way in which you manage connections. Something like:
Open a connection at startup.
On
@app.before_request
verify that the connection wasn’t closed by the database (or by any other reason). If it’s closed, open it again, otherwise, recycle the connection.You may be interested in a pooled connection.
Edit
This is a bad advice, see @coleifer comment for clarification.
Yes, you can use a connection string to configure the pooled database connection.
http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#connect
The kwargs are parsed from the URL query parameters.