When core Moodle chat is used in "gui_ajax" mode, each open chat windows triggers Ajax update every 3 seconds:
https://github.com/moodle/moodle/blob/MOODLE_38_STABLE/mod/chat/gui_ajax/index.php#L78
This in turn causes mod/chat/chat_ajax.php script to update lastping field in chat_users table:
https://github.com/moodle/moodle/blob/master/mod/chat/chat_ajax.php#L146
This does not scale well - it will cause a lot of DB writes when many users use the chat activity. And the problem gets pretty serious on installations when chat is commonly used - as users will usually keep the window open & running in the background for a long time.
I propose to check the current lastping time and not update it more often than (say) once every minute.