Skip to content

Memory usage increases with subject and threadpool scheduler #582

Description

@damianoct

Hi,

I'm using rxpy for an event-driven application and after some stress tests I noticed a strange behaviour on memory usage.
I've created a simple script to reproduce the issue.


from rx.scheduler import ThreadPoolScheduler
from rx.subject import Subject
import rx.operators as ops
from threading import current_thread
import multiprocessing
import rx
import time

pool_scheduler = ThreadPoolScheduler(multiprocessing.cpu_count())

pipeline = [ops.map(lambda x: x**2)]

pipeline.append(ops.observe_on(pool_scheduler))


s = Subject()
s.pipe(*pipeline).subscribe(on_next=lambda x: print("{}, thread: {}".format(x, current_thread().name)))

for i in range(100000000000):
    s.on_next(i)

input()

I'm using memory-profile library for tracing the memory usage of this script, after 30 seconds of run the result is the following:

Screen Shot 2021-09-01 at 11 02 59 AM

The memory is growing linearly.

If I place a time.sleep(0.1) inside the for loop the memory usage is steady.


from rx.scheduler import ThreadPoolScheduler
from rx.subject import Subject
import rx.operators as ops
from threading import current_thread
import multiprocessing
import rx
import time

pool_scheduler = ThreadPoolScheduler(multiprocessing.cpu_count())

pipeline = [ops.map(lambda x: x**2)]

pipeline.append(ops.observe_on(pool_scheduler))


s = Subject()
s.pipe(*pipeline).subscribe(on_next=lambda x: print("{}, thread: {}".format(x, current_thread().name)))

for i in range(100000000000):
    s.on_next(i)
    time.sleep(0.1)

input()

Screen Shot 2021-09-01 at 11 04 59 AM

I don't know if the problem is related to python / rxpy or if I'm using the library in a wrong way.

PS: the memory usage is steady if I get rid of scheduler and everything is executed on the main thread.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions