ugo-nama-kun / gym_torcs

MIT License
409 stars 163 forks source link

How to improve the frames per second in gym_torcs.py #31

Open yanpanlau opened 7 years ago

yanpanlau commented 7 years ago

Hi, I am working on the new projects in gym_torcs which requires faster frames per second. I found that in

ob, reward, done, _ = env.step(action)

which calls line 122-124 in gym_torcs.py

client.respond_to_server() 
# Get the response of TORCS 
client.get_servers_input() 

is very slow. the 2 lines above took 0.2 seconds (so 5 fps)

Do you know if there is anyway I can improve the fps?

Thanks,

Ben

kschan commented 7 years ago

I am also having this same issue. Control updates are getting sent at 5Hz which seems excessively slow

spsancti commented 6 years ago

Hi, the same issue here. Any workaround for now?

kschan commented 6 years ago

If you don't need to use the gym-torcs environment specifically, I found using the SCRC patch on TORCS and the Snakeoil Python client together worked very nicely, I get 20Hz game state and control input. See my repo for code: https://github.com/kschan/torcs_scripts

Sorry if the code is not very clean.

spsancti commented 6 years ago

Hi, @kschan , thanks for your work! Is there any possibility to enable image input?

kschan commented 6 years ago

Not via my code! I bet you could do something clever though.

spsancti commented 6 years ago

Oh, I'll try to figure it out.

BTW, vtorcs-RL-color already has scr-patch applied.

I did some profiling, and the most time-consuming part of the code is:

sockdata,addr= self.so.recvfrom(data_size)

which is called at line 168 in snakeoil3_gym.py. It takes about 180 ms to complete. Also, if I make socket non-blocking, client is still waiting about 180 ms, so issue is on the TORCS side.

@yanpanlau , @ugo-nama-kun , do you have any ideas about this?

spsancti commented 6 years ago

Well, I have figured it out. It is just here.

I got sustainable results with RCM_MAX_DT_ROBOTS of 0.05. If I make it less, TORCS eventually freezes. Also, in scr_server and here I changed the number of bots to 1 so not to waste precious resources.

And, here it is! As for me, it is really good result!