Skip to content

Commit

Permalink
fix: Optimize some code
Browse files Browse the repository at this point in the history
  • Loading branch information
cnzakii committed Aug 24, 2024
1 parent 6c625bd commit 8afd66e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 16 deletions.
8 changes: 5 additions & 3 deletions dubbo/cluster/monitor/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
_cpu_invocation = RpcInvocation(
"org.apache.dubbo.MetricsService",
"cpu",
b"",
str(1).encode("utf-8"),
attributes={
common_constants.CALL_KEY: UnaryCallType,
},
Expand Down Expand Up @@ -164,11 +164,13 @@ def get_service_handler() -> RpcServiceHandler:
)

@staticmethod
def get_cpu_usage(*args) -> bytes:
def get_cpu_usage(interval) -> bytes:
"""
Get the CPU usage.
:param interval: The interval.
:type interval: bytes
:return: The CPU usage.
:rtype: bytes
"""
float_value = CpuUtils.get_total_cpu_usage()
float_value = CpuUtils.get_total_cpu_usage(interval=int(interval.decode("utf-8")))
return str(float_value).encode("utf-8")
2 changes: 1 addition & 1 deletion dubbo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import socket

__all__ = ["EventHelper", "FutureHelper", "NetworkUtils"]
__all__ = ["EventHelper", "FutureHelper", "NetworkUtils", "CpuUtils"]

from typing import List, Tuple

Expand Down
9 changes: 1 addition & 8 deletions samples/registry/zookeeper/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def unary(self, request):

if __name__ == "__main__":
registry_config = RegistryConfig.from_url(
"zookeeper://127.0.0.1:2181?loadbalance=cpu"
"zookeeper://127.0.0.1:2181"
)
bootstrap = dubbo.Dubbo(registry_config=registry_config)

Expand All @@ -47,13 +47,6 @@ def unary(self, request):

unary_service_stub = UnaryServiceStub(dubbo_client)

time.sleep(5)

result = unary_service_stub.unary(unary_unary_pb2.Request(name="world"))

print(result.message)

time.sleep(10)

result = unary_service_stub.unary(unary_unary_pb2.Request(name="world"))
print(result.message)
4 changes: 0 additions & 4 deletions samples/registry/zookeeper/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,4 @@ def handle_unary(request):
# start the server
server = bootstrap.create_server(service_config).start()

server1 = bootstrap.create_server(
ServiceConfig(service_handler, port=50052)
).start()

input("Press Enter to stop the server...\n")

0 comments on commit 8afd66e

Please sign in to comment.