apache / pulsar-client-python

Apache Pulsar Python client library
https://pulsar.apache.org/
Apache License 2.0
49 stars 38 forks source link

There is a memory leak,I need help #208

Closed kansnow closed 3 months ago

kansnow commented 3 months ago
import time
import pulsar
import sys
import gc

client = pulsar.Client('pulsar://localhost:6650')

def connect_to_pulsar():
    producer = None
    try:
        producer = client.create_producer('my-topic')
        producer.send(b'Hello Pulsar!')
    except Exception as e:
        print(f"Connection to Pulsar failed: {e}")
    finally:
        size = sys.getsizeof(client)
        print(f"Memory usage of {client.__class__.__name__} object: {size} bytes")
        if producer:
            producer.close()
        gc.collect()

for _ in range(1000000):
    connect_to_pulsar()
    time.sleep(1)

client.close()

there is my code,I am using pulsar-client with version 2.9.1. when I run this code in python3, Process memory keeps growing. Where exactly is the problem?

merlimat commented 3 months ago

Can you try with latest version 3.4.0? https://pypi.org/project/pulsar-client/

kansnow commented 3 months ago

Can you try with latest version 3.4.0? https://pypi.org/project/pulsar-client/

ok, I'll try upgrading the version

kansnow commented 3 months ago

Can you try with latest version 3.4.0? https://pypi.org/project/pulsar-client/

Thank you very much. I used the top command to check the memory usage of the process. After upgrading the version, the memory did not grow anymore