Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolve watcher high cpu usage #211

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pro4jhu
Copy link

@pro4jhu pro4jhu commented Feb 20, 2025

version: 2.0.1
python version: 3.8.13
operate system: CentOS Linux release 7.9.2009

while syntax cause high cpu use, because of the different mechanism, below code when run in linux, it will use hign cpu. windows normal

test code:

import nacos
import yaml
from flask import Flask

app = Flask(name)

class NacosCofig:
namespace = "public"
group = "DEFAULT_GROUP"
server_name = "test"
server_port = "7004"
data_id = "test"
server_addresses = "http://127.0.0.1:8848"
server_ip = "127.0.0.1"

client = nacos.NacosClient(NacosCofig.server_addresses, namespace=NacosCofig.namespace)
yaml_data = yaml.load(client.get_config(NacosCofig.data_id, NacosCofig.group), Loader=yaml.FullLoader)

def start_nacos():
global yaml_data, client
client.add_config_watcher(NacosCofig.data_id, NacosCofig.group, _modify_config_cb)

def _modify_config_cb(config):
global yaml_data
yaml_data = yaml.load(client.get_config(NacosCofig.data_id, NacosCofig.group), Loader=yaml.FullLoader)
print(yaml_data)

def service_register():
global client
client.add_naming_instance(NacosCofig.server_name, NacosCofig.server_ip, NacosCofig.server_port,
ephemeral=False, group_name=NacosCofig.group, heartbeat_interval=5)

if name == 'main':
start_nacos()
service_register()
app.run(debug=False, port=7004, host="0.0.0.0")

before:
image
after:
image

@CLAassistant
Copy link

CLAassistant commented Feb 20, 2025

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants