Simulation is very slow on Windows Server 2019

Report crashes, strange behaviour, or apparent bugs
Post Reply
yonghun.shin
Posts: 4
Joined: 03 Nov 2020, 07:10

Simulation is very slow on Windows Server 2019

Post by yonghun.shin »

When I run simulation with child threaded script on Windows Server 2019,
Simulation is very slow.
child non threaded script and customization script is working good.
Only child Threaded script is not well.


How to fix this problem?

coppelia
Site Admin
Posts: 8368
Joined: 14 Dec 2012, 00:25

Re: Simulation is very slow on Windows Server 2019

Post by coppelia »

Hello,

the way a threaded script works is by imitating the behaviour of coroutines. From within a threaded script you can explicitely yield (i.e. switch thread) with sim.switchThread, to give control back to the simulator, until next simulation step. If you don't do that, the yield/switch will be automatic after around 2 ms (i.e. preemptive thread switching). This timing can be adjusted if needed with sim.setThreadSwitchTiming or forbidden with sim.setThreadAutomaticSwitch.

As an example, following threaded script will waste precious processing time, since the collision is being checked several times within a same simulation step. Also you do not have control on how often collision is checked within a same simulation step:

Code: Select all

while true do
    sim.checkCollision(...)
end
Much better would be:

Code: Select all

sim.setThreadAutomaticSwitch(false) -- forbid preemptive thread switching
while true do
    sim.checkCollision(...)
    sim.switchThread() -- only explicitely switch thread. This thread will resume when t has become t+dt
end
sim.setThreadAutomaticSwitch(true) -- restore preemtive thread switching
In above second example, collision checking will be performed exactly once per simulation step.

Cheers

yonghun.shin
Posts: 4
Joined: 03 Nov 2020, 07:10

Re: Simulation is very slow on Windows Server 2019

Post by yonghun.shin »

Hello,

I mean just I run simulation with provided scene files. ( e.g. inverseKinematicsOf144DofManipulator.ttt )

I have not made threaded script.

This Symptom is occured only windows server, not windows10 or linux.

coppelia
Site Admin
Posts: 8368
Joined: 14 Dec 2012, 00:25

Re: Simulation is very slow on Windows Server 2019

Post by coppelia »

Oh... that is strange. In next release you will be able to use script coroutines instead of threads, i.e. everything will become more lightweight and easier to use/understand in regards to threads. Additionally, threads/coroutines will be usable in any type of scripts: this should resolve your problem.

But maybe you can try this simple threaded child script code and tell me the output:

Code: Select all

while true do
    local st=sim.getSystemTimeInMs(-1)
    sim.switchThread()
    print(sim.getSystemTimeInMs(st))
end
edit: as a background information: in current CoppeliaSim (V4.1.0), real threads are used to mimic coroutines.

Cheers

yonghun.shin
Posts: 4
Joined: 03 Nov 2020, 07:10

Re: Simulation is very slow on Windows Server 2019

Post by yonghun.shin »

coppelia wrote:
03 Nov 2020, 10:41
But maybe you can try this simple threaded child script code and tell me the output:

Code: Select all

while true do
    local st=sim.getSystemTimeInMs(-1)
    sim.switchThread()
    print(sim.getSystemTimeInMs(st))
end


I added only child threaded script in empty scene.

script body is refer to below.

Code: Select all

function sysCall_threadmain()
    -- Put some initialization code here


    while true do
        local st=sim.getSystemTimeInMs(-1)
        sim.switchThread()
        print(sim.getSystemTimeInMs(st))
    end
end

function sysCall_cleanup()
    -- Put some clean-up code here
end

-- See the user manual or the available code snippets for additional callback functions and details
Output :

Code: Select all

[CoppeliaSim:info]   Adding a dummy...
[CoppeliaSim:info]   done.
[sandboxScript:info]   Simulation started.
38
16
6
6
6
41
52
45
110
38
71
66
62
6
8
6
18
51
69
68
38
42
72
43
46
63
13
4
6
6
6
6
5
27
71
29
67
56
76
38
144
40
6
7
5
5
12
5
107
39
51
76
127
73
70
7
4
5
6
7
23
51
32
57
63
54
43
36
62
62
36
7
5
18
5
39
58
42
104
44
34
62
39
67
15
5
11
5
7
4
37
28
63
56
52
57
60
25
52
6
6
7
15
22
50
46
40
88
45
66
126
14
5
6
8
5
5
6
24
85
64
47
44
72
132
66
20
5
4
4
4
4
5
37
39
58
36
107
43
73
40
77
32
4
5
6
7
6
7
33
34
117
31
70
59
54
47
106
6
9
7
8
19
34
64
103
64
42
53
65
5
8
8
58
31
52
36
114
67
34
68
71
25
13
6
10
6
46
48
28
42
38
81
77
44
55
6
6
9
6
58
88
22
65
52
55
40
87
35
49
22
6
47
43
91
70
29
56
57
76
11
6
7
9
45
54
64
126
77
41
62
54
24
6
92
45
66
19
61
48
119
53
8
20
7
8
59
114
59
68
59
55
40
5
24
8
37
[sandboxScript:info]   simulation stopping...
70
39
32
66
53
5
5
6
4
12
44
66
75
[sandboxScript:info]   Simulation stopped.
Could you let me know.
When release next version?

coppelia
Site Admin
Posts: 8368
Joined: 14 Dec 2012, 00:25

Re: Simulation is very slow on Windows Server 2019

Post by coppelia »

I suspect the issue is related to thread switch resolution timing... on Windows, CoppeliaSim client application uses timeBeginPeriod(1) in order to set that resolution to 1ms. But apparently this doesn't work on your operating system somehow. Maybe there is a system setting that can be adjusted.

Next release will be in January 2021. We are probably able to provide you with a beta version if needed.

Cheers

yonghun.shin
Posts: 4
Joined: 03 Nov 2020, 07:10

Re: Simulation is very slow on Windows Server 2019

Post by yonghun.shin »

I have tested timeBeginPeriod(1) in my system.

Code: Select all

#include <stdio.h>
#include <Windows.h>

#pragma comment(lib, "winmm.lib")

int main()
{
    int count = 100;

    timeBeginPeriod(1); // 주기를 1ms로 설정

    while (count-- > 0)
    {
        printf("%d\n", ::timeGetTime());
    }

    timeEndPeriod(1); // 설정된 주기를 해제

    getchar();
    return 0;
}
Output

Code: Select all

772051328
772051328
772051328
772051328
772051328
772051328
772051328
772051328
772051328
772051328
772051328
772051328
772051328
772051328
772051328
772051328
772051328
772051328
772051328
772051328
772051328
772051328
772051328
772051328
772051328
772051328
772051328
772051328
772051328
772051328
772051333
772051345
772051351
772051351
772051351
772051351
772051351
772051351
772051351
772051351
772051351
772051351
772051351
772051351
772051351
772051351
772051351
772051351
772051351
772051352
772051352
772051352
772051352
772051352
772051352
772051352
772051352
772051352
772051352
772051352
772051352
772051352
772051352
772051352
772051352
772051352
772051352
772051352
772051352
772051352
772051353
772051353
772051353
772051353
772051353
772051353
772051353
772051353
772051353
772051353
772051353
772051353
772051353
772051353
772051353
772051353
772051353
772051353
772051353
772051353
772051353
772051354
772051356
772051356
772051357
772051357
772051357
772051358
772051358
772051359

It was looked something bad...
there are nothing to do for the issue?

In additionally, When Process Priority of the CoppeliaSim set to Realtime, It looks working good.
But, This way is required Administrator Permission to set REALTIME_PRIORIRY.

coppelia
Site Admin
Posts: 8368
Joined: 14 Dec 2012, 00:25

Re: Simulation is very slow on Windows Server 2019

Post by coppelia »

yonghun.shin wrote:
05 Nov 2020, 00:51
In additionally, When Process Priority of the CoppeliaSim set to Realtime, It looks working good.
But, This way is required Administrator Permission to set REALTIME_PRIORIRY.
I think this is your best option, on that machine, until we release next version of CoppeliaSim (V4.2.0), which will support threading/coroutines for all script types.

Cheers

Post Reply