mdbq 4.0.114__tar.gz → 4.0.115__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of mdbq might be problematic. Click here for more details.
- {mdbq-4.0.114 → mdbq-4.0.115}/PKG-INFO +1 -1
- mdbq-4.0.115/mdbq/__version__.py +1 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq/redis/redis_cache.py +36 -57
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq.egg-info/PKG-INFO +1 -1
- mdbq-4.0.114/mdbq/__version__.py +0 -1
- {mdbq-4.0.114 → mdbq-4.0.115}/README.txt +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq/__init__.py +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq/auth/__init__.py +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq/auth/auth_backend.py +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq/auth/rate_limiter.py +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq/js/__init__.py +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq/js/jc.py +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq/log/__init__.py +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq/log/mylogger.py +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq/myconf/__init__.py +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq/myconf/myconf.py +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq/mysql/__init__.py +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq/mysql/deduplicator.py +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq/mysql/mysql.py +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq/mysql/s_query.py +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq/mysql/unique_.py +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq/mysql/uploader.py +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq/other/__init__.py +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq/other/download_sku_picture.py +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq/other/error_handler.py +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq/other/otk.py +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq/other/pov_city.py +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq/other/ua_sj.py +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq/pbix/__init__.py +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq/pbix/pbix_refresh.py +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq/pbix/refresh_all.py +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq/redis/__init__.py +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq/redis/getredis.py +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq/route/__init__.py +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq/route/analytics.py +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq/route/monitor.py +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq/route/routes.py +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq/selenium/__init__.py +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq/selenium/get_driver.py +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq/spider/__init__.py +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq.egg-info/SOURCES.txt +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq.egg-info/dependency_links.txt +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/mdbq.egg-info/top_level.txt +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/setup.cfg +0 -0
- {mdbq-4.0.114 → mdbq-4.0.115}/setup.py +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
VERSION = '4.0.115'
|
|
@@ -68,9 +68,9 @@ class CacheStatsCollector:
|
|
|
68
68
|
self.namespace_stats = defaultdict(int)
|
|
69
69
|
|
|
70
70
|
# 同步提交控制
|
|
71
|
-
self.submit_interval = self.config.get('submit_interval',
|
|
71
|
+
self.submit_interval = self.config.get('submit_interval', 600) # 每隔N秒定时提交一次(期间有新操作时)
|
|
72
72
|
self.last_submit_time = time.time()
|
|
73
|
-
self.
|
|
73
|
+
self.last_operation_count = 0 # 上次提交时的操作总数
|
|
74
74
|
|
|
75
75
|
def record_operation(self, operation: str, response_time: float = 0, namespace: str = ""):
|
|
76
76
|
"""记录操作统计"""
|
|
@@ -120,67 +120,47 @@ class CacheStatsCollector:
|
|
|
120
120
|
})
|
|
121
121
|
|
|
122
122
|
def _check_and_submit(self):
|
|
123
|
-
"""
|
|
123
|
+
"""检查并提交统计数据 """
|
|
124
124
|
if not self.mysql_pool:
|
|
125
125
|
return
|
|
126
126
|
|
|
127
127
|
current_time = time.time()
|
|
128
128
|
time_since_last_submit = current_time - self.last_submit_time
|
|
129
|
-
should_submit = False
|
|
130
|
-
reason = ""
|
|
131
|
-
|
|
132
|
-
# 重构后的提交逻辑:
|
|
133
|
-
# 1. 每N次操作提交一次,但每X秒内只能提交一次(防止频繁提交)
|
|
134
|
-
# 2. 每隔X秒提交一次,但必须满足N次操作
|
|
135
|
-
|
|
136
|
-
if self.stats['total_operations'] % self.submit_interval == 0:
|
|
137
|
-
# 达到操作次数阈值
|
|
138
|
-
if time_since_last_submit >= self.min_submit_interval:
|
|
139
|
-
# 满足时间间隔要求,可以提交
|
|
140
|
-
should_submit = True
|
|
141
|
-
reason = f"达到操作次数阈值({self.submit_interval}次)且满足时间间隔({self.min_submit_interval}秒)"
|
|
142
|
-
else:
|
|
143
|
-
# 时间间隔不够,延迟提交
|
|
144
|
-
remaining_time = self.min_submit_interval - time_since_last_submit
|
|
145
|
-
logger.debug("操作次数达标但时间间隔不足,延迟提交", {
|
|
146
|
-
'instance_name': self.instance_name,
|
|
147
|
-
'process_id': self.process_id,
|
|
148
|
-
'total_operations': self.stats['total_operations'],
|
|
149
|
-
'time_since_last_submit': round(time_since_last_submit, 2),
|
|
150
|
-
'remaining_time': round(remaining_time, 2)
|
|
151
|
-
})
|
|
152
|
-
elif time_since_last_submit >= self.min_submit_interval:
|
|
153
|
-
# 达到时间间隔阈值
|
|
154
|
-
if self.stats['total_operations'] >= self.submit_interval:
|
|
155
|
-
# 满足操作次数要求,可以提交
|
|
156
|
-
should_submit = True
|
|
157
|
-
reason = f"达到时间间隔阈值({self.min_submit_interval}秒)且满足操作次数({self.submit_interval}次)"
|
|
158
|
-
else:
|
|
159
|
-
# 操作次数不够,不提交
|
|
160
|
-
logger.debug("时间间隔达标但操作次数不足,暂不提交", {
|
|
161
|
-
'instance_name': self.instance_name,
|
|
162
|
-
'process_id': self.process_id,
|
|
163
|
-
'total_operations': self.stats['total_operations'],
|
|
164
|
-
'required_operations': self.submit_interval,
|
|
165
|
-
'time_since_last_submit': round(time_since_last_submit, 2)
|
|
166
|
-
})
|
|
167
129
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
130
|
+
# 提交逻辑:每隔固定秒数且期间有新操作则提交
|
|
131
|
+
if time_since_last_submit >= self.submit_interval:
|
|
132
|
+
# 检查是否有新的操作(与上次提交时相比)
|
|
133
|
+
new_operations = self.stats['total_operations'] - self.last_operation_count
|
|
134
|
+
|
|
135
|
+
if new_operations > 0:
|
|
136
|
+
# 有新操作,提交统计数据
|
|
137
|
+
try:
|
|
138
|
+
self._submit_to_mysql()
|
|
139
|
+
self.last_submit_time = current_time
|
|
140
|
+
self.last_operation_count = self.stats['total_operations']
|
|
141
|
+
|
|
142
|
+
logger.info("统计数据定时提交", {
|
|
143
|
+
'instance_name': self.instance_name,
|
|
144
|
+
'process_id': self.process_id,
|
|
145
|
+
'total_operations': self.stats['total_operations'],
|
|
146
|
+
'new_operations': new_operations,
|
|
147
|
+
'time_since_last_submit': round(time_since_last_submit, 2),
|
|
148
|
+
'submit_interval': self.submit_interval
|
|
149
|
+
})
|
|
150
|
+
except Exception as e:
|
|
151
|
+
logger.error("统计数据提交失败", {
|
|
152
|
+
'instance_name': self.instance_name,
|
|
153
|
+
'process_id': self.process_id,
|
|
154
|
+
'error': str(e)
|
|
155
|
+
})
|
|
156
|
+
else:
|
|
157
|
+
# 无新操作,跳过提交但更新时间
|
|
171
158
|
self.last_submit_time = current_time
|
|
172
|
-
logger.
|
|
159
|
+
logger.debug("定时检查:期间无新操作,跳过提交", {
|
|
173
160
|
'instance_name': self.instance_name,
|
|
174
161
|
'process_id': self.process_id,
|
|
175
162
|
'total_operations': self.stats['total_operations'],
|
|
176
|
-
'time_since_last_submit': round(time_since_last_submit, 2)
|
|
177
|
-
'reason': reason
|
|
178
|
-
})
|
|
179
|
-
except Exception as e:
|
|
180
|
-
logger.error("统计数据提交失败", {
|
|
181
|
-
'instance_name': self.instance_name,
|
|
182
|
-
'process_id': self.process_id,
|
|
183
|
-
'error': str(e)
|
|
163
|
+
'time_since_last_submit': round(time_since_last_submit, 2)
|
|
184
164
|
})
|
|
185
165
|
|
|
186
166
|
def _submit_to_mysql(self):
|
|
@@ -284,6 +264,7 @@ class CacheStatsCollector:
|
|
|
284
264
|
self.response_times.clear()
|
|
285
265
|
self.namespace_stats.clear()
|
|
286
266
|
self.last_submit_time = time.time()
|
|
267
|
+
self.last_operation_count = 0
|
|
287
268
|
|
|
288
269
|
|
|
289
270
|
class CacheSystemState(enum.Enum):
|
|
@@ -300,8 +281,7 @@ class CacheConfig:
|
|
|
300
281
|
def __init__(self, **kwargs):
|
|
301
282
|
# 基础配置
|
|
302
283
|
self.default_ttl = kwargs.get('default_ttl', 3600) # 默认过期时间(秒)
|
|
303
|
-
self.
|
|
304
|
-
self.stats_initial_delay = kwargs.get('stats_initial_delay', 300) # 最少N秒提交一次
|
|
284
|
+
self.stats_submit_interval = kwargs.get('stats_submit_interval', 600) # 每隔N秒定时提交一次(期间有新操作时)
|
|
305
285
|
self.enable_stats = kwargs.get('enable_stats', True) # 是否启用统计功能
|
|
306
286
|
self.max_value_size = kwargs.get('max_value_size', 10 * 1024 * 1024) # 最大值大小(字节)
|
|
307
287
|
self.cache_prefix = kwargs.get('cache_prefix', 'cache') # 缓存键前缀
|
|
@@ -343,8 +323,7 @@ class SmartCacheSystem:
|
|
|
343
323
|
mysql_pool=self.mysql_pool,
|
|
344
324
|
config={
|
|
345
325
|
'instance_name': self.instance_name,
|
|
346
|
-
'submit_interval': self.config.
|
|
347
|
-
'min_submit_interval': 300, # 最少N秒提交一次
|
|
326
|
+
'submit_interval': self.config.stats_submit_interval, # 每隔N秒定时提交一次(期间有新操作时)
|
|
348
327
|
'table_name': self.config.table_name,
|
|
349
328
|
'db_name': self.config.db_name
|
|
350
329
|
}
|
mdbq-4.0.114/mdbq/__version__.py
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
VERSION = '4.0.114'
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|