-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Example of creating Observable from an I/O source #840
Comments
Is it okay for the parallel execution to be unordered or do you need the output to remain in the same order as coming from the file? The difference is significant in how the problem is tackled.
If nobody subscribes then the Thus, a |
unordered is fine |
For working with large/infinite streams of text I recommend you look at the rxjava-string contrib module. There are a few basic operators working with strings and byte arrays. I just submitted a pull request #843 to add a
|
I' not actually interested in string files, I've just used that as a simple example without having to explain the binary format of the file we're parsing :-) |
The from code is a good starting place though, thanks! |
Take a look at the |
@abersnaze should @benjchristensen how am I supposed to use |
Yes. If oncompleted is not called things tend to hang forever.
|
@abersnaze is that a bug you'll be fixing soon? |
@benjchristensen I wrapped my but this results in an This is very representative of problems I face on an recurring basis and it appears that the current I am aware that you've said (on the mailing list) that this is a work in progress and there are plans to allow customisation of the parallel strategy. For me it would be ideal if the producer and consumer were seen as pots of atomic work (e.g. |
Could you write a unit test in Java without the various dependencies of that code that demonstrates the OOM issue? |
@benjchristensen if it helps, absolutely! I might drop the StringObservables too, and just use an infinite stream of integers or something |
Thank you, it definitely would. I'd like to use the unit test to track down the issue, resolve it and put in the codebase. If you submit it as a PR I'll merge it in as I work on fixing it. |
@benjchristensen I'm struggling with gradle.
I might just do this as a unit test in my repo and then copy it over when I can compile and open in IntelliJ. |
actually, writing this might have to run as part of a separate "low heap size" test package. It'll obviously pass if the default jvm flags are used. |
@benjchristensen please find test... you'll need to run it with a really small heap (like 5m) to see the problem. My Output:
|
Thank you, I'll play with this. |
to avoid the need to change the memory settings, the test could be easily changed to return arrays of 10 to 100MB. That outta cause OOMs with your default test settings (what is your default?) |
@benjchristensen see trivial update that OOMs with default JVM settings. |
@benjchristensen I should like to draw your attention to my experiment at https://github.com/fommil/rx-playground/commit/26d39e030dc10e9c7c99be638537b55473be8537 This is horrendously inefficient at the moment, and ugly, but the principles are there. In a nutshell, I have defined an interface The algorithm is pretty simple, effectively: produce if the buffer is getting low (and we're not already blocking on the producer in another thread), otherwise consume (if there is anything to consume), otherwise rest (by giving the thread back to the pool). There is a pool of The performance could be greatly improved by reducing (or eliminating) the need to use locks, and the code could be cleaned up (dramatically) by a few simple refactors. However, a simple test (in the Next steps could be:
|
The backpressure concerns of this issue are being tracked in #1000 and worked on as part of the Reactive Streams (https://github.com/reactive-streams/reactive-streams) project. If there is anything out of this discussion that you'd like to contribute back, please submit it as part of one of the existing contrib-modules or as a new one. |
I'd like to see an example of something simple like reading lines from a File, in Scala.
It would then be incredibly useful to see:
The text was updated successfully, but these errors were encountered: