Skip to content

cpython3.11.6 memory is more than cpython3.9.9 #154929

Description

@xinsheng3-hw

Feature or enhancement

Proposal:

test.py

import json, os, time, sys, subprocess
from threading import Thread

P = '/usr/bin/ports_info'


def e(c):
    try:
        p = subprocess.Popen(c.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
        o, _ = p.communicate(timeout=3600)
        return p.poll(), o.rstrip('\n')
    except:
        return 1, ''


class T(Thread):
    def run(s):
        while 1:
            try:
                d = json.load(open(P))
                for n in d.get('ovs', []):
                    if n.get('name') == 'physnet2':
                        b = {b['name']: b for b in d.get('bond_info', [])}
                        if b.get(n['interface'], {}).get('bond_mode') != 'balance-xor':
                            q = [p for p in d.get('base_ports', []) if p != d.get('PXE', '')]
                            if q and d.get('ovs', [{}])[0].get('share_nic_ovs_dpdk') == 'True':
                                r, o = e(f'ip link show {q[0]}')
                                if not r:
                                    r2, o2 = e('sudo evsadm exec bond/show --json')
                                    if not r2 and len(json.loads(o2)[0].get('slaves_info', [])) >= 2:
                                        e(f'sudo ifconfig {q[0]} {"up" if "DOWN" in o else "down" if "UP" in o else ""}')
            except:
                pass
            time.sleep(1)


if __name__ == '__main__':
    if os.fork() == 0:
        T().start()
        while 1:
            try:
                d = json.load(open(P))
                if d.get('PXE') and d.get('Logic-phyMapInfo', {}).get('nic1') == 'unknow': e(
                    f'sudo discoveryTool {d["PXE"]}')
            except:
                pass
            time.sleep(60)
    else:
        sys.exit(0)

/usr/bin/ports_info file content : (for exp)


{
    "PXE": "eth0",
    "base_ports": ["eth0", "eth1", "eth2"],
    "port-capability": {
        "eth0": "1G",
        "eth1": "10G",
        "eth2": "10G"
    },
    "bond_info": [
        {
            "name": "trunk0",
            "bond_mode": "balance-xor"
        },
        {
            "name": "bond0",
            "bond_mode": "active-backup"
        }
    ],
    "ovs": [
        {
            "name": "physnet1",
            "interface": "bond0",
            "mappingtype": "dpdk",
            "share_nic_ovs_dpdk": "True",
            "hinic_mode": "OSP"
        },
        {
            "name": "physnet2",
            "interface": "bond1",
            "mappingtype": "hwbond"
        }
    ],
    "Logic-phyMapInfo": {
        "nic0": "eth0",
        "nic1": "unknow"
    }
}

test rss method :

PID=$(pgrep -f "test.py" | head -1) && pmap -x $PID 2>/dev/null | grep total &&  kill $PID

python v3.9.9 ccb0e6a rss : 7308k
python v3.11.6 8b6ee5b rss: 8592k
python v3.13.6 89f78413c85a7b42f9b636dd6defccd0ed03ee39 rss: 9556k
python v3.14.0rc2 08c753ebdcc99134545c99bf70ee65842efd4f57 rss: 14236k

Is there any solution to optimize the memory?

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    performancePerformance or resource usage

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions