So I am developing an application, which has a 'strong' parallel structure, and since time is important for me, I thought about creating 4 threads for each 'subwork' (assuming running on 4 cores device). If the 4 subworks are executed sequentially it will be a great loss of potential.
The OS will handle which threads run on which cores. All you need to do is use AsyncTasks or threads to set it up for parallel processing and it will take advantage of it if it can. You can find a more information on the topic in this qualcomm blog post.
I do not believe that you have access to the individual cores - this is handled by the Android kernel. However, as long as you implement your 4 "threads" as Java Thread you should be fine, seeing as they can execute concurrently independant of your main Android Activity. You can find additional information on using a Thread in Android here: http://developer.android.com/reference/java/lang/Thread.html
You cannot control the kernel yourself (without root) i belive, but android should use all the threads itself, so you dont need to do anything at your end.
This might help, if you want to run many activityes at the same time - Can you have two activities running at the same time?
Related
I have the following problem: I need to run an android app in an emulator, get to a certain state in it, after which I want to fork the process into two and do different actions in the app starting from that state.
Example: I want to open Yelp in the emulator, after which I want to search for "Coffee", then fork the process into 10, and in each child process open different coffee place.
The particular problem is how to perform the fork.
I've been trying to explore solutions to this problem, and found no easy way to do it. The options I explored the possibility of so far are:
Actually fork the app process within the emulator. This appears to be completely impossible.
Somehow fork the emulator process with an app running in it. There's no easy way to fork an external process, so I guess I would have to change the emulator code to fork from within when certain external event happens.
Put the emulator in some sort of a VM, which supports hot cloning. I haven't found any VM that actually supports it without serious downtime.
Ideally I want a solution that doesn't double the memory (similar to how fork in Linux works), and that is not associated with a significant downtime, though any solution that doesn't have the above two properties would also be acceptable.
Okay, that's quite the task. Intuitively, I would expect option 2 to be the most promising.
Alternatively, have you considered writing an UIAutomator script and having it run in parallel or consecutively across a few devices? The bonus criteria would definitely not be met, but after sufficient runtime you might get what you're looking for.
Bring emulator into the state at which you want to fork
Save snapshot
Spawn emulator, specifying snapshot
Run UIAutomator script
Record findings
GOTO 3
I have some things my app needs to do periodically
these things - if done while running the app itself, affect its performance - in terms, they make it VERY BAD
they have to do with downloading large jsons from the server and caching downloaded images
if i do all those things in a service, and the app is running while the service is running as well - will it affect any of the app's performance?
will the service take up any app memory allocated by dalvik ?
If you run the Service in a separate process, it will have less of an impact on the other parts of your app, but it will make communicating to the Service more difficult.
Are you saying that you know these operations affect performance? If so, what signs are you seeing? You may be running into problems because you're trying to run everything on the main thread; if so, using a background thread may solve the problem.
This question already has answers here:
Stresstest Memory on Android
(2 answers)
Closed 3 years ago.
I've been reading up on the Android dalvik, and I was curious as to how one would go about stress testing the Dalvik to evaluate its stability. I understand the Dalvik is meant for memory an processor constrained devices. So would allocating a lot of memory/increasing frequency of some CPU cores and then launching multiple applications be a way to test the stability?
I also understand that each independent process gets itsown instance of the Dalvik. So another possibility to stress the Dalvik would be to launch multiple applications that share a single process and a single instance of the Dalvik and see how stable the Dalvik is.
I would like to to know if either of these are good ways to measure the stability of the Dalvik. If both of them are good ways, which one would be a better test?
Thanks!
It's difficult to stress every part of a VM all at once.
You can write memory stress tests that exercise the heap and the garbage collector, synchronization stress tests (like the JSR-166 java.util.concurrent test suite), CPU stress tests that do lots of integer and floating-point computations on different cores simultaneously. And so on.
The trick is to write a test that does what you think it does -- a surprising number of "multi-core" tests end up single-threaded because of unexpected dependencies -- and whose results can be evaluated for correctness. A test that successfully causes instability isn't useful unless that fact is communicated to the user in some way. Making the VM crash is a pretty good way. :-)
Running multiple apps and services in the same process is theoretically possible but rare in practice. I don't think you'd actually be able to stress the system out any better this way, since only one app is in the foreground at a time, and if you're making requests of a service one thread will wait for the response while the other runs. You're better off just have one app with multiple threads, so you can control exactly what each does and how they interact.
Before you can do any of this, you need to define the scope of "stability". Simply running many apps isn't going to turn up anything, since there are hundreds of millions of devices running billions of instances of Dalvik with essentially no failures due to the VM itself (but any number due to bugs in apps, the framework, 3rd-party libraries, etc). Dalvik hasn't changed much since Android 4.0 (Ice Cream Sandwich) shipped two years back.
Does single thread application use all the 4 core in a Quad-core phone.
I searched this a lot and found some articles that says yes and some saying no. some articles even say the android OS doesn't utilize the 4 core.
Is android capable of using all 4 cores in an Quad core processor?
Does single thread application utilize multi core?
The answer is YES.
Android is basically built upon Linux kernel which does utilize mulit-core.
As far as single-threaded-application is concerned, remember that a thread can not be executed in-parts on different cores simultaneously. So although your single-thread can be executed by different cores at different point in times, it can not be sub-divided and executed by different cores at the same time.
Having said that, please be aware that chipset manufacturers like Qualcomm are developing intelligent processors capable of sub-dividing your single-threaded app code (if and only if there are mutually exclusive parts) into multiple threads and have it run on different cores. Here again, the basic principle remains same - in order to utilize multi-core, the single thread was sub-divided into multiple threads.
To get the most out of your multi-core chip, you would rather create a multi-threaded app, with maximum possible asynchronous threads, so as to have optimum utilization of maximum number of cores. Hope this clears.
EDIT:
This also translates to - An app that does not make use of multiple asynchronous threads (or any other parallelism construct) will NOT use more than one core.
Yes. Android 3.0 is the first version of the platform designed to run on either single or multicore processor architectures.
Even a single-threaded application can benefit from parallel processing on different cores.
For example, if your application uses a media server, then the media processing and your UI rendering application logic can run on different cores at the same time. Also, the garbage collector can run on a different core.
Say your using graphics. To render the same your app can use multi cores. You can check the same at the link below.
https://youtu.be/vQZFaec9NpA?t=459 (Graphics and performance)
http://android-developers.blogspot.in/2010/07/multithreading-for-performance.html
Check this pdf. Scroll down to slide 22. Might be useful
http://elinux.org/images/1/11/Application-Parallelization-Android-KlaasVanGend.pdf
Is there any way of creating a process or thread in a specific core in Android?
edited for more info: the idea is that having two cores, I would like to run 2 different processes or threads in 2 different cores. Specifically, what I want to do is use 100% of the CPU of the phone, no matter how many cores the phone has.
Is there any way of creating a process or thread in a specific core in Android?
No, sorry.
the idea is that having two cores, I would like to run 2 different processes or threads in 2 different cores.
That is for the OS to decide, not you.
Specifically, what I want to do is use 100% of the CPU of the phone, no matter how many cores the phone has.
No developer should have that as an objective, outside of benchmarking applications and the like.