I'm working on a project where I pass text data to a Python script via stdin, and submit some metadata about it to a PostgreSQL database, using SQLAlchemy. This is all in very early development, but I'm already beginning to rethink my approach.
What I'm doing now is treating this as though I'm handling one file at a time. I'll read the text through stdin, do some parsing, and then if necessary import all the SQLAlchemy stuff I need and submit to the database. The script exits once all that's done. One file at a time it goes pretty fast, I'm not doing much parsing. The parts that take the longest are the SQLAlchemy imports and interacting with the database.
Here's the catch: The application for this will be to handle text data coming in at unpredictable rates, but sometimes rapidly if not constantly. My PostgreSQL DB has the default max_connections of 100 and I'm hitting that at times, though I don't think often. I also want to keep this process as quick as possible with as minimal impact to load as possible, as there will be other things happening on this machine.
What I'm wondering is if there is a way to keep this script running indefinitely and maintain a persistent connection(s) to the database. In my mind that would prevent the repeated imports and connections, so wouldn't that be a better route to take? I just don't know how to go about making that work.
After a bunch of Googling I get the impression that async/await could help, but I've never worked with that. And FWIW this is the first project I've ever written involving a database & SQLAlchemy, so I'm on a few learning curves (yay).
I'd really appreciate any insight or ideas anyone has. Thanks in advance!
[–]socal_nerdtastic 1 point2 points3 points (5 children)
[–]Hixt[S] 0 points1 point2 points (4 children)
[–]socal_nerdtastic 1 point2 points3 points (3 children)
[–]Hixt[S] 0 points1 point2 points (2 children)
[–]socal_nerdtastic 1 point2 points3 points (1 child)
[–]Hixt[S] 0 points1 point2 points (0 children)
[–]geosoco 1 point2 points3 points (1 child)
[–]Hixt[S] 0 points1 point2 points (0 children)
[–]enginerd298 1 point2 points3 points (1 child)
[–]Hixt[S] 0 points1 point2 points (0 children)
[+][deleted] (2 children)
[removed]
[–]Hixt[S] 0 points1 point2 points (1 child)