I'm using Python script to check if user requested exists. using:
import MySQLdb
from flask import Flask, request, abort
app = Flask(__name__)
try:
db = MySQLdb.connect('xxx1','my_username','my_password','my_db_name')
db1 = MySQLdb.connect('xxx2','my_username','my_password','my_db_name')
db2=
db3=
except MySQLdb.OperationalError as e:
print "Caught an exception : " + str(.message)
@app.route('/')
@app.route('/<path:path>')
def page(path = ''):
user = request.args.get('user', None)
if not mac:
abort (403)
cursor = db.cursor()
query = 'Select ID from f_member where Name=%s'
db.commit()
cursor execute(query, (user, ))
row = cursor.fetchone()
cursor.close()
#cursor.db1 here
if row == None and row1 == None:
abort (403)
return 'OK', 200
if __name__ == '__main__':
app.run(host=host, port=port)
Then i have 5 nginx servers with this:
location = /auth {
proxy_pass http://xxx.xxx$request_uri;
proxy_pass_request_body off;
proxy_set_header Content_Lenght "";
proxy_set_header X-Real-IP $remote_addr;
So the thing is, this script checks if user is found in one of the databases, if true then access the page. Problem is my user list is now getting up to 5k users. and when i run the .py script it runs so fast (even with errors 403 people who are trying to connect), then broken pipe starts to show up. Seems like it is getting overloaded, is there a better way to handle my script so it runs better and more efficient?