Skip to content

Commit 9974b67

Browse files
committed
fix: 修复每个模块重复导入的问题
1 parent d03ff39 commit 9974b67

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

core/dashboard.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
from . import utils
1212

1313
from . import scheduler
14-
from .web import routes as route
14+
from .web import (
15+
routes as route,
16+
qps as web_qps
17+
)
1518
from aiohttp import web
1619

1720
@dataclass
@@ -39,7 +42,7 @@ class SystemInfo:
3942
memory_usage: int
4043
connection: ConnectionStatistics
4144
clusters: list[ClusterInfo]
42-
qps: 'WebValue'
45+
qps: int
4346

4447
@dataclass
4548
class CounterValue:
@@ -69,20 +72,10 @@ def get_json(self):
6972
"tcp": item.value.connection.tcp,
7073
"udp": item.value.connection.udp,
7174
},
72-
"qps": item.value.qps.qps
75+
"qps": item.value.qps
7376
}} for item in self._data
7477
]
7578

76-
@dataclass
77-
class WebValue:
78-
qps: int = 0
79-
80-
def clone(self):
81-
return WebValue(
82-
self.qps
83-
)
84-
85-
qps = WebValue()
8679
counter = Counter()
8780
process = psutil.Process(os.getpid())
8881

@@ -116,6 +109,7 @@ async def _(request: web.Request):
116109
route.static("/assets", "./assets")
117110

118111
def record():
112+
global web_qps
119113
memory = process.memory_info()
120114
connection = process.connections()
121115
stats = SystemInfo(
@@ -126,9 +120,9 @@ def record():
126120
udp=len([c for c in connection if c.type == socket.SOCK_DGRAM])
127121
),
128122
clusters=[],
129-
qps=qps.clone()
123+
qps=web_qps
130124
)
131-
qps.qps -= stats.qps.qps
125+
web_qps -= stats.qps
132126
counter.add(stats)
133127

134128
async def init():

core/web.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
from aiohttp import web
99
from aiohttp.web_urldispatcher import SystemRoute
1010

11-
from . import dashboard
1211
from . import units
1312
from . import config
1413
from .logger import logger
1514
import ssl
1615

16+
qps: int = 0
17+
1718
class SNIHelper:
1819
def __init__(self, data: bytes) -> None:
1920
self.buffer = io.BytesIO(data)
@@ -45,7 +46,8 @@ def get_sni(self):
4546

4647
@web.middleware
4748
async def middleware(request: web.Request, handler: Any) -> web.Response:
48-
dashboard.qps.qps += 1
49+
global qps
50+
qps += 1
4951
with request.match_info.set_current_app(app):
5052
address = request.remote or ""
5153
try:

0 commit comments

Comments
 (0)