Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI freezes on fdatasync #7952

Closed
rnz opened this issue May 26, 2020 · 35 comments
Closed

UI freezes on fdatasync #7952

rnz opened this issue May 26, 2020 · 35 comments
Labels

Comments

@rnz
Copy link

rnz commented May 26, 2020

Steps to reproduce

About ui freezes

  1. run strace with ignore some operations
sudo strace -e 'trace=!recvmsg,poll,writev,stat,futex' -p $(pgrep Telegram) 2>&1 | egrep -v 'read\(5|write\(5'
  1. type some text in message input box
  2. catch some freezes on fdatasync:
getpid()                                = 69543
getpid()                                = 69543
access("/home/rnz/.TelegramDesktop/tdata/D877F783D5D3EF8C/E66391AC0BDD1C96s", F_OK) = 0
access("/home/rnz/.TelegramDesktop/tdata/D877F783D5D3EF8C/E66391AC0BDD1C96s", W_OK) = 0
lstat("/home/rnz/.TelegramDesktop/tdata/D877F783D5D3EF8C/E66391AC0BDD1C96s", {st_mode=S_IFREG|0664, st_size=364, ...}) = 0
openat(AT_FDCWD, "/home/rnz/.TelegramDesktop/tdata/D877F783D5D3EF8C", O_RDWR|O_CLOEXEC|O_TMPFILE, 0600) = 41
access("/home/rnz/.TelegramDesktop/tdata/D877F783D5D3EF8C/E66391AC0BDD1C96s", R_OK) = 0
access("/home/rnz/.TelegramDesktop/tdata/D877F783D5D3EF8C/E66391AC0BDD1C96s", W_OK) = 0
access("/home/rnz/.TelegramDesktop/tdata/D877F783D5D3EF8C/E66391AC0BDD1C96s", X_OK) = -1 EACCES (Permission denied)
fchmod(41, 0664)                        = 0
fstat(41, {st_mode=S_IFREG|0664, st_size=0, ...}) = 0
write(41, "TDF$o\210\36\0\0\0\0\360_\230r\7\27@K\v\356\0t\221\240\262\36\334\203-\227\326"..., 268) = 268
lseek(41, 0, SEEK_SET)                  = 0
fdatasync(41)                           = 0
linkat(AT_FDCWD, "/proc/self/fd/41", AT_FDCWD, "/home/rnz/.TelegramDesktop/tdata/D877F783D5D3EF8C/E66391AC0BDD1C96s", AT_SYMLINK_FOLLOW) = -1 EEXIST (File exists)
linkat(AT_FDCWD, "/proc/self/fd/41", AT_FDCWD, "/home/rnz/.TelegramDesktop/tdata/D877F783D5D3EF8C/E66391AC0BDD1C96s.cvzUPK", AT_SYMLINK_FOLLOW) = 0
close(41)                               = 0
rename("/home/rnz/.TelegramDesktop/tdata/D877F783D5D3EF8C/E66391AC0BDD1C96s.cvzUPK", "/home/rnz/.TelegramDesktop/tdata/D877F783D5D3EF8C/E66391AC0BDD1C96s") = 0
unlink("/home/rnz/.TelegramDesktop/tdata/D877F783D5D3EF8C/E66391AC0BDD1C960") = -1 ENOENT (No such file or directory)
unlink("/home/rnz/.TelegramDesktop/tdata/D877F783D5D3EF8C/E66391AC0BDD1C961") = -1 ENOENT (No such file or directory)

Expected behaviour

No UI freezes on background io operations

Actual behaviour

Freezes.

Configuration

Operating system:
$ lsb_release -a
LSB Version: core-11.1.0ubuntu2-noarch:printing-11.1.0ubuntu2-noarch:security-11.1.0ubuntu2-noarch
Distributor ID: Ubuntu
Description: Ubuntu 20.04 LTS
Release: 20.04
Codename: focal

Version of Telegram Desktop:
2.1.7

Installation source (Linux Only) - the official website / GitHub releases / flatpak / snap / distribution package:
GitHub releases

Used theme:
Night

Additional info:
My /home placed on zfs pool (two hdd in mirror with zlog on nvme ssd) and zfs before version 0.8 didn't support O_DIRECT and operation fdatasync didn't wait disk io. But now zfs support O_DIRECT and operations such as fdatasync now have write time penalties. And for example now when zfs run scrub Telegram is almost completly unusable by freezes because too often call sync operations and not exec this operations in background and have impact on the user interface.

I think fdatasync doesn't need for Telegram - linux fs drivers, vfs and also zfs write stack already have own tunable strategy for sync. But if Telegram is need fsyncdata - that operation must be run in background without impact UI

Also Telegram have too many operations stat("/etc/localtime", ...) on mouse hover action on groups:

...
stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=1535, ...}) = 0
stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=1535, ...}) = 0
stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=1535, ...}) = 0
...

I think this is overhead too

@ilya-fedin
Copy link
Contributor

Also Telegram have too many operations stat("/etc/localtime", ...) on mouse hover action on groups:

Looks like Qt parses this file on each time request and this can't be solved in tdesktop:
https://github.com/qt/qtbase/blob/dev/src/corelib/time/qtimezoneprivate_tz.cpp#L1124

@ilya-fedin
Copy link
Contributor

  1. type some text in message input box
  2. catch some freezes on fdatasync:

Probably it's due to recent switching to QSaveFile to avoid logout on power outage, and it is called when saving drafts 🤔
2ad48f1

@rnz
Copy link
Author

rnz commented May 27, 2020

Also Telegram have too many operations stat("/etc/localtime", ...) on mouse hover action on groups:

Looks like Qt parses this file on each time request and this can't be solved in tdesktop:
https://github.com/qt/qtbase/blob/dev/src/corelib/time/qtimezoneprivate_tz.cpp#L1124

Why tdesktop need a time request when hovering over the mouse cursor?

@ilya-fedin
Copy link
Contributor

Why tdesktop need a time request when hovering over the mouse cursor?

🤔 probably, for tooltip or to update the time on the item

@rnz
Copy link
Author

rnz commented May 27, 2020

@ilya-fedin I don't saw any actions by hovering (no hints, no time updates) in tdesktop

And I think this is wrong(or old style) call: if (open(save, 's')) {
May be need use save.open() with https://doc.qt.io/qt-5/qiodevice.html#OpenModeFlag-enum ?

@ilya-fedin
Copy link
Contributor

And I think this is wrong(or old style) call: if (open(save, 's')) {

No, it's FileWriteDescriptor::open

@ilya-fedin
Copy link
Contributor

ilya-fedin commented May 27, 2020

I don't saw any actions by hovering (no hints, no time updates) in tdesktop

You can't see any difference since it's the same post probably

@cypa
Copy link

cypa commented Jun 12, 2020

my disk io is slow and freezes are crazy long while I type new message ...
"QSaveFile ... and it is called when saving drafts" - is it synchronous disk io on typing new message? crazy! из пушки по воробьям! how do I disable drafts at all?

@rnz
Copy link
Author

rnz commented Jun 13, 2020

This is so stupid bug - when running some io operations on filesystem (such as scrubbing on zfs) - Telegram is complete unusable.

@cypa
Copy link

cypa commented Jun 14, 2020

friend, put dir like this
.local/share/TelegramDesktop/tdata/D877F783D5D3EF8C
to tmpfs into RAM
that's a makeshift but it works, no lags

@rnz
Copy link
Author

rnz commented Jun 30, 2020

friend, put dir like this
.local/share/TelegramDesktop/tdata/D877F783D5D3EF8C
to tmpfs into RAM
that's a makeshift but it works, no lags

Thanks but this workaround is ugly.

I think behaviour - when changes in input box is put to disk - must be configurable (off, custom period) and of course next need to be fix ui bug with freezes.

@GaurangTandon
Copy link

@cypa Thanks, I tried this trick, it did entirely get rid of the freezing. Awesome! However, now my telegram desktop resets every time I restart my pc. Which means I have to login again, enter otp, and enter 2fa password every time, and it resets all my settings too :( This is expected since I loaded Telegram Desktop into RAM, but still :(

@jonathonf
Copy link

Another workaround is to use eatmydata/libeatmydata, e.g. eatmydata telegram-desktop or LD_PRELOAD=/usr/lib/libeatmydata.so telegram-desktop

It "is designed to transparently disable fsync and friends" - the lack of write safety won't be a concern if you're already putting this data in volatile storage.

I've updated my desktop shortcuts already... 😁

@rnz
Copy link
Author

rnz commented Aug 23, 2020

Another workaround is to use eatmydata/libeatmydata, e.g. eatmydata telegram-desktop or LD_PRELOAD=/usr/lib/libeatmydata.so telegram-desktop

It "is designed to transparently disable fsync and friends" - the lack of write safety won't be a concern if you're already putting this data in volatile storage.

I've updated my desktop shortcuts already...

This workaroud unfortunately not working...

@jonathonf
Copy link

Not working in what way, @rnz ?

You can't get the preload to work, or it doesn't fix the issue completely?

@rnz
Copy link
Author

rnz commented Oct 2, 2020

Not working in what way, @rnz ?
You can't get the preload to work, or it doesn't fix the issue completely?

It doesn't fix the issue - freezes on input still present when telegram save text from input field

@Dimensional
Copy link

Dimensional commented Oct 28, 2020

This is rather annoying. Telegram sometimes flat out crashes when it hangs due to this, though that hasn't happened for a few weeks. I disabled Spellcheck and it still hangs when saving the draft. Is it trying to write to an actual file or save the draft to a cache in memory? Since I'm running on HDD, the freezing would be very prominent with the seek time.

@rnz
Copy link
Author

rnz commented Nov 6, 2020

@ilya-fedin hi man! Is there any progress with fix this bug?

@ilya-fedin
Copy link
Contributor

I don't know, ask @john-preston

@rnz
Copy link
Author

rnz commented Nov 6, 2020

@john-preston same question?

@john-preston
Copy link
Member

@rnz I have a patch that moves all fdatasync-s to the background thread, I think I'll add it to the next beta release.

@grandsilence
Copy link

@john-preston Still no solution even in the latest beta? The slowness during typing is very annoying.

@cyb3rd4d
Copy link

If that can help, I recently discovered that the TRIM was not enabled on my system because I encrypted my SSD through dm-crypt and in that case TRIM is not automatically enabled for security purposes: https://wiki.archlinux.org/index.php/Dm-crypt/Specialties#Discard/TRIM_support_for_solid_state_drives_(SSD)
I enabled the TRIM and got excellent performances since then.

@grandsilence
Copy link

@MartialGeek I already have TRIM activated for all drives. But it doesn't help. I will try to transfer Telegram Data to RAM drive.

@ilya-fedin
Copy link
Contributor

I will try to transfer Telegram Data to RAM drive.

You had a different issue with spellchecker rather than with fdatasync IIRC, hadn't you?

@grandsilence
Copy link

grandsilence commented Feb 23, 2021

@ilya-fedin Yes, there was a problem with the spellchecker when the processor got overloaded when typing long words or ".........." (many special characters). This problem has been fixed, thanks for that. But the problem with microlags while typing doesn't disappear even if you turn off spellchecker.

OS: Windows 10 x64 1803
Telegram Version: 2.5.9 (beta)

@ilya-fedin
Copy link
Contributor

This problem has been fixed, thanks for that.

Why don't you close your issue then?

@grandsilence
Copy link

@ilya-fedin I'm going to close now, referring to this thread.

@john-preston
Copy link
Member

@grandsilence Today (I hope) will be a next stable release, then maybe some bug-fix releases and then I hope to deploy a new beta version where I'll try to enable moving all fdatasync-s to a background thread.

@grandsilence
Copy link

@john-preston Thank you very much. I'll be waiting.

@rnz
Copy link
Author

rnz commented May 1, 2021

How long to wait?

@grandsilence
Copy link

@john-preston any news about the issue?

@Younes-L
Copy link

Younes-L commented May 5, 2021

@grandsilence @rnz new beta 2.7.5 with fdatasync in background thread, check it out

If it doesn't fix the freezing for you there's still cypa's trick which works flawlessly

@grandsilence
Copy link

@Younes-L Switched to new beta 2.7.5. Looks like the problem has been solved!
Finally, all the micro-lags disappeared during typing.
Thank you so much ❤

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests