I have a big problem with MICROSOFT SQL FROM KUBERNETES
I have setup my entire cluster.
I thought everything is working fine, then observed that all the api calls are very slow..
SETUP:
My cluster with services is running in my office server room, and i have microsoft sql server running on windows machine just beside it.
Now my requests to that sql server are 5-6x slower than my earlier setup where, requests used to go from services running on IIS on windows machine to MS sql server running on windows.
i ran profiler and saw that
pyodbc.connect is taking 90% of the time
The query which is taking 500ms to be executed on windows machine is taking 5.2seconds out of which 4.46 is consumed by pyodbc.connect
PLEASE HELP
I found this https://www.unixodbc.org/doc/conn_pool.html
and updated my odbcinst.ini file
[ODBC]
Trace = No
Trace File = /tmp/sql.log
Pooling = Yes
[ODBC Driver 18 for SQL Server]
Description=Microsoft ODBC Driver 18 for SQL Server
Driver=/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.4.so.1.1
UsageCount=1
CPTimeout=60
This is how i use pyodbc to read query
DEFAULT_DRIVER_UNIX = "/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.4.so.1.1"
DEFAULT_DRIVER_ODBC_UNIX = "/usr/lib64/libmsodbcsql-18.so"
if platform.system() == "Linux":
DEFAULT_DRIVER = DEFAULT_DRIVER_UNIX
DEFAULT_DRIVER_ODBC = DEFAULT_DRIVER_UNIX
def create_db_string(*, server, database, username, password, driver=DEFAULT_DRIVER):
return (
f"Driver={driver};"
f"Server={server};"
f"Database={database};"
f"uid={username};"
f"pwd={password};"
"Trusted_Connection=no;"
"integratedSecurity=false;"
"TrustServerCertificate=yes;"
)
def read_from_db(db_string, query, sorting_index=None, descending=False):
"""given database connection string, and a query returns a sorted list
of queried items from database"""
conn = pyodbc.connect(db_string)
cursor = conn.cursor()
cursor.execute(query)
return_list = list(cursor.fetchall())
if sorting_index is not None:
return_list.sort(key=lambda x: x[sorting_index], reverse=descending)
return return_list
I changed odbcinst.ini file according to the link provided above. Still no change.
Do i have to change code aswell?
How to solve this issue.