[Question]Running multiple simulators
@lawrencelomax I see that one factor that limits number of simulators one can have on machine is CPU used by Native App under test itself. And, I see that same app on simulator takes more CPU than its on actual real device. I see this behavior same for few apps that I tried. Have you guys run into this issue? How many simulators you guys have on a host? what's your host configuration?
One of the biggest limiting factors worth considering is that by performing identical work on multiple simulators, on the same host, at the same time will lead to a very uneven loading of the machine. Booting and launching an App are CPU and IO intensive, performing this work at the same time across multiple simulators will severely limit the amount of Simulators that you can run in parallel.
If you employ a strategy that means that this work is more evenly distributed over time, then you will likely see that you don't have such a spiky load profile. The net result will be that you can get much more out of your machines. Another thing worth bearing in mind is that you can have Simulators 'pre-booted' in anticipation of a test running. This means that the tests don't have to pay the cost of booting the Simulator itself.
There are certain sections of the SeleniumConf video that may be helpful to you.
@lawrencelomax My apology for late response. I totally missed this. We have all our sessions always pre-warmed i.e. we have simulators launched with app install. We do launch app per test and we do not keep app launched. We have 3 simulators running on macmini(i5) and what I have seen is if 3 simulators are happened to be doing scroll or typing actions' (both are CPU intensive jobs) at same time on 2 different simulators then tests start failing. How do you solve this issue or you guys don't face such issue?
3 Simulators should just work fine. It's important to have either a Monitor or some HDMI dongle connected to the Mac Mini to activate its GPU. If you don't have one connected, you could give it a try, connect one, and then see if that changes something. For us this makes a huge difference.
Thanks @plu . I will give that try. We don't have that Monitor or HDMI dongle connected. I will give HDMI dongle a try and see if it helps. I remote into one of such machine and tried to look into system setting to check whether it is currently using GPU but could not find any setting indicating that. How did you confirm this helps? by measuring test performance?
Yes, measuring test performance. If the HDMI dongle gets removed, our test suite runs much longer and tests start to fail randomly (timeouts). We even have a check in our CI scripts that verify the HDMI dongle is connected, before any tests are executed.
# Verify the HDMI dongle is connected. This activates the GPU and is important for Simulator performance.
system_profiler SPDisplaysDataType | grep -q 'fit Headless' || (echo "Are you sure the fit Headless HDMI dongle is connected?" && exit 1)
Thanks a lot @plu . I will give a try with this.
@plu I did give a try with machine connected to monitor. I did see 5-7 minutes improvement, not whole lot. Failures due to CPU issues were intermittent so I have to run it for some more time to conclude. But I do see one amazing thing i.e. I was able to run tests across 5 simulators which was just not possible. It did slow down test run time a little but I have not see failures yet. I am going to experiment more around this. Thanks for all help.
Glad to hear it helped!
How many simulators do you guys run in parallel ? What is your machine spec for that? Do you guys use XCUITEST based framework or KIF/EarlGrey?
You should be able to get substantially more than 3 simulators running in parallel on a recent Mac mini. Bear in mind that having one with 8Gb of memory or an SSD will make a big difference to the boot speeds, much of this is IO bound.
Are you splaying out your boots so that they don't execute at the same time? You might see test execution suffer more if you boot all of them at the same time. In terms of test execution, we do have Simulators running WebDriverAgent, which is an XCUITest bundle.
Thanks @lawrencelomax Yes we do have 8 GB and SSDs. Our system is such that there could never be simulator boot and test can happen at same time. So that is not case. What I have seen is AUT itself takes lots of CPU sometimes. What @plu suggested (using display emulator) is helping a little.
Another suggestion is to avoid the need for rendering the display of a Simulator in the first place. If you look at the --direct-launch argument, you'll see that it's possible to boot a Simulator without needing to create an Application and Window for it. This may lower system utilization as you'll likely not need to see the Simulator screen when it's being automated. Instead you can use video recording/streaming/screenshots to view the screen.
Thanks @lawrencelomax . I am okay with not seeing Simulator. I have tried this but surprisingly I don't see difference. Theoretically there has to be some. But it is not visible. I am also passing hidport will that affect performance. I want to be able send command to hid if I am using --direct-launch.
You are only able to send commands to the hid using --direct-launch, you can't use this otherwise. I doubt that connecting the hid will effect performance, since this is what Simulator.app already does.
Thanks, that's what I thought. I am running 5 simulators now and it has been reliable so far. I have one more question : How do you guys run browser tests on multiple simulators on same host? We use magical port 27753 to communicate with webkit to execute test on safari on simulator. But if multiple simulators are launched there is only one simulator has that service running with magical port 27753 to execute test on webkit.
Do you guys treat safari as native app and run test or there is different way to communicate with webkit?
I'm not sure of the use-case of this magical port, but found this which may be what you are looking at.
With regards to additional services that run alongside multiple simulators, a simple way of doing this is to never rely on the default port for any additional services that you may run, and have each simulator own a shard of ports. For example each simulator will have a range of ports reserved:
PORT_OFFSET + 0the port for--httpinfbsimctlPORT_OFFSET + 1the port forWebDriverAgentPORT_OFFSET + 2the port for your arbitrary service.
This is where PORT_OFFSET = BASE_OFFSET + (SIMULATOR_INDEX * RANGE_SIZE).
If you're using some WebKit proxy service, this would be analogous to running WebDriverAgent on the same host for multiple Simulators. Just make a guarantee that the ports are free for each simulator and always manually specify and calculate the values of these ports. You may find some inspiration in one of our recent posts.
We just released idb. a new tool that improves significantly over fbsimctl. We recommend switching over. As part of our renewed commitment to this repo we are cleaning up old issues and will be monitoring and reviewing more closely from now on. if you still think this issue is relevant feel free to reopen