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

Clear Memory occupied by volley request queue #220

Closed
sky9971 opened this issue Sep 12, 2018 · 3 comments
Closed

Clear Memory occupied by volley request queue #220

sky9971 opened this issue Sep 12, 2018 · 3 comments

Comments

@sky9971
Copy link

sky9971 commented Sep 12, 2018

I have an android application in which I need multiple volley request queue's to be maintained for different iot devices. My app needs to communicate with each iot device on separate request queue for faster response.
But because I have new request queue being created for each new iot device object, my app is going out of memory.
I want to clear the memory occupied by previous request queue..
Is it possible by any means??

@jpd236
Copy link
Collaborator

jpd236 commented Sep 12, 2018

Are you really sure you need multiple request queues? Have you observed a bottleneck from using a single queue? I'm surprised that you would find that multiple queues would help you here rather than (say) increasing the size of the NetworkDispatcher thread pool, if in fact your network threads were being used up. But it'd be good to know where the bottleneck actually is.

In any case, RequestQueue#stop will shut down all of the underlying threads, which should free up nearly all of the memory used by a queue.

@jpd236 jpd236 closed this as completed Sep 12, 2018
@sky9971 sky9971 changed the title Cler Memory occupied by volley request queue Clear Memory occupied by volley request queue Sep 13, 2018
@sky9971
Copy link
Author

sky9971 commented Sep 13, 2018

Thanks for your fast reply. Actually my application needs to send about 5 to 10 requests to my single iot device in a second when the user is interacting with the device. I started from using default httpurlconnection inside asyntask but it was slow and queued up consecutive commands, waited for the first command to be finished off before the next one could be processed.
I tried okhttp, it also suffered with the same slow and delayed response.
At last I came on volley, I followed the singleton pattern in the start but it also gave me delayed response like it would take minutes to complete around 20 requests. I adapted to multiple request queue pattern to achieve the above stated speed by creating separate request handler for each of my iot device. In multiple request queue pattern I could send upto 10 to 15 requests per second to around 7 iot devices. I also optimised my requestqueue by cancelling previous requests by using tag and executing only present and latest request.
when I am creating new request handler's I made sure to call
RequestHandler.Stop()
on previous handler but it did not help. My application would still crash while creating new request handler throw me this error

pthread_create failed: couldn't allocate 1069056-bytes mapped space: Out of memory

i'm looking for a better way to clean up resources and memory occupied by volley's request handler. That will save me the time for looking for a new http request handler.

@jpd236
Copy link
Collaborator

jpd236 commented Sep 13, 2018

Not sure there's much I can offer from the Volley side - all we can do is stop the threads.

Longer term, we're hoping to work on an asynchronous architecture that will scale better for large numbers of parallel requests - see #181. Unfortunately I can't offer an ETA on that or anything.

I will say that from my own experience, seeing pthread_create issues may not actually be due to being out of memory per se. IIRC Nexus 5X and 6P have a bug that causes pthread_create to fail even when there should be plenty of memory. Not sure if other devices might have similar issues.

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

No branches or pull requests

2 participants