feat: 增强 upsert_video 方法,添加缓冲区长度和操作时间的调试信息
This commit is contained in:
parent
1c4823d633
commit
ed73a94a4f
18
DB.py
18
DB.py
@ -1,4 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
|
from turtledemo.penrose import start
|
||||||
|
|
||||||
import redis
|
import redis
|
||||||
import pymysql
|
import pymysql
|
||||||
import time
|
import time
|
||||||
@ -445,7 +447,7 @@ class DBSA:
|
|||||||
push_record = staticmethod(lambda row: print("[退回Redis]", row["v_xid"]))
|
push_record = staticmethod(lambda row: print("[退回Redis]", row["v_xid"]))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def upsert_video(cls, data: Dict):
|
def upsert_video(cls, data):
|
||||||
data = copy.deepcopy(data)
|
data = copy.deepcopy(data)
|
||||||
data.setdefault("a_id", 0)
|
data.setdefault("a_id", 0)
|
||||||
data.setdefault("history_status", "")
|
data.setdefault("history_status", "")
|
||||||
@ -476,13 +478,17 @@ class DBSA:
|
|||||||
with cls._lock:
|
with cls._lock:
|
||||||
cls._buf_op.append(op_row)
|
cls._buf_op.append(op_row)
|
||||||
cls._buf_vid.append(vid_row)
|
cls._buf_vid.append(vid_row)
|
||||||
|
buf_len = len(cls._buf_vid)
|
||||||
if len(cls._buf_op) >= cls.FLUSH_EVERY_ROWS:
|
print(f"DB缓冲 -> xid={data['v_xid']}, level={data['level']}, buffer={buf_len}")
|
||||||
|
if buf_len >= cls.FLUSH_EVERY_ROWS:
|
||||||
need_flush = True
|
need_flush = True
|
||||||
|
flush_reason = "ROWS"
|
||||||
elif time.time() - cls._last_flush >= cls.FLUSH_INTERVAL:
|
elif time.time() - cls._last_flush >= cls.FLUSH_INTERVAL:
|
||||||
need_flush = True
|
need_flush = True
|
||||||
|
flush_reason = "TIME"
|
||||||
|
|
||||||
if need_flush:
|
if need_flush:
|
||||||
|
print(f"DBSA 落 ({flush_reason}) ...")
|
||||||
cls.flush()
|
cls.flush()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -519,11 +525,13 @@ class DBSA:
|
|||||||
|
|
||||||
if not op_rows and not vid_rows:
|
if not op_rows and not vid_rows:
|
||||||
return
|
return
|
||||||
|
start = time.time()
|
||||||
try:
|
try:
|
||||||
cls._bulk_insert(op_rows)
|
cls._bulk_insert(op_rows)
|
||||||
cls._bulk_upsert(vid_rows)
|
cls._bulk_upsert(vid_rows)
|
||||||
|
elapsed = time.time() - start
|
||||||
|
print(f"[DBSA] 成 op={len(op_rows)} video={len(vid_rows)} time={elapsed:.3f}s")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("[DBSA] 批写失败:", e)
|
print(f"[DBSA] flush FAIL: {e} op={len(op_rows)} video={len(vid_rows)}")
|
||||||
for row in vid_rows:
|
for row in vid_rows:
|
||||||
cls.push_record(row)
|
cls.push_record(row)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user