Hello,
I have, what I would say, is a standard questdb configuration but reading from the questdb database is incredibly slow. My set up is:
questdb-9.0.3 that I downloaded from https://github.com/questdb/questdb/releases/download/9.0.3/questdb-9.0.3-rt-linux-x86-64.tar.gz
Then, I run ./questdb.sh start.
I have 30 sensors recording data at 2^14 Hz and I’m saving 2 minutes of data and reading 2 minutes of data. I can save the data into the database following the Python dataframe example:
import pandas as pd
from questdb.ingress import Sender
import numpy as np
import datetime as dt
from time import time
conf = 'http::addr=127.0.0.1:9000;'
fs = 2**14
step = dt.timedelta(seconds=1)
Nchans = 30
i = 0
start = dt.datetime.now()
# Sweep data - make 2 minutes
for j in range(120):
x = np.arange(Nchans*fs).reshape((fs, Nchans)) + i
names = ['Chan'+str(i) for i in range(1, Nchans+1)]
df = pd.DataFrame(x, columns=names, copy=True)
i += Nchans * fs
tic = time()
print(f'Saving {j} second...')
with Sender.from_conf(conf) as sender:
sender.dataframe(df, table_name='sensor',
at=start+step)
toc = time()
print(f'{toc-tic:.2f} seconds elapsed.')
This is fairly slow taking a total of 15-20 seconds, but it’s not unbearable.
When I try to read from questdb following the Python basic example:
import time
import psycopg
conn = psycopg.connect(
host='127.0.0.1',
port=8812,
user='admin',
password='quest',
dbname='qdb',
autocommit=True # Important for QuestDB
)
tic = time.time()
with conn.cursor(binary=True) as cur:
cur.execute("SELECT * FROM sensor;")
data = cur.fetchall()
toc = time.time()
print(f'{toc-tic:.2f} seconds elapsed.')
conn.close()
It takes 19 seconds !! to read 1.9M rows or 2 minutes of data. While the questdb console takes around 20-30 milliseconds.
What am I doing wrong with the Python example that the questdb console is doing instead? Or what can I do to speed things up? Thanks,