telegramdesktop / tdesktop

Telegram Desktop messaging app
https://desktop.telegram.org/
Other
26.29k stars 5.22k forks source link

High CPU load #3640

Closed kmare closed 3 years ago

kmare commented 7 years ago
### Steps to reproduce 1. Simply start Telegram 2. Let it run for a while (could be hours or even days) 3. At some point it will start consuming lots of CPU ### Expected behaviour It shouldn't spend all that CPU load ### Actual behaviour It just consumes CPU time till the program is restarted ### Configuration **Operating system:** Fedora Linux 25 on one i7 laptop and one i5 desktop. Same thing on an Ubuntu 16.04 laptop. **Version of Telegram Desktop:** 1.1.11 (previous versions too. IIRC 1.0 was ok) **Used theme**: Any theme
Logs: Insert logs here (if necessary)

running: top -H -p will return: top - 19:57:37 up 4 days, 21:42, 1 user, load average: 0.83, 1.34, 1.37 Threads: 20 total, 1 running, 19 sleeping, 0 stopped, 0 zombie %Cpu(s): 9.3 us, 0.7 sy, 0.0 ni, 89.0 id, 0.1 wa, 0.5 hi, 0.3 si, 0.0 st KiB Mem : 16291228 total, 3390260 free, 5596580 used, 7304388 buff/cache KiB Swap: 8191996 total, 8191996 free, 0 used. 8155060 avail Mem

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
5470 smee 20 0 2686276 653620 100172 S 10.3 4.0 8:19.68 QThread
13349 smee 20 0 2686276 653620 100172 S 9.0 4.0 7:38.81 QThread
13346 smee 20 0 2686276 653620 100172 S 7.7 4.0 6:25.81 QThread
5471 smee 20 0 2686276 653620 100172 S 6.7 4.0 5:41.01 QThread
5482 smee 20 0 2686276 653620 100172 S 6.0 4.0 5:39.49 QThread
13348 smee 20 0 2686276 653620 100172 S 4.7 4.0 3:56.05 QThread
4829 smee 20 0 2686276 653620 100172 R 4.0 4.0 4:22.86 QThread
13347 smee 20 0 2686276 653620 100172 S 3.7 4.0 3:12.62 QThread
27411 smee 20 0 2686276 653620 100172 S 1.7 4.0 22:55.85 Telegram
27412 smee 20 0 2686276 653620 100172 S 0.0 4.0 0:33.49 QXcbEventReader
27413 smee 20 0 2686276 653620 100172 S 0.0 4.0 0:06.78 QDBusConnection
27415 smee 20 0 2686276 653620 100172 S 0.0 4.0 0:13.68 Qt bearer threa
27416 smee 20 0 2686276 653620 100172 S 0.0 4.0 0:00.00 gmain
27417 smee 20 0 2686276 653620 100172 S 0.0 4.0 0:00.08 gdbus
27432 smee 20 0 2686276 653620 100172 S 0.0 4.0 0:00.20 QThread
27433 smee 20 0 2686276 653620 100172 S 0.0 4.0 0:01.95 QThread
27434 smee 20 0 2686276 653620 100172 S 0.0 4.0 0:00.00 QThread
27436 smee 20 0 2686276 653620 100172 S 0.0 4.0 0:06.02 MTP::internal::
4205 smee 20 0 2686276 653620 100172 S 0.0 4.0 0:00.00 Qt HTTP thread
27321 smee 20 0 2686276 653620 100172 S 0.0 4.0 0:00.00 Qt HTTP thread

etehtsea commented 7 years ago

Same problem on i7/macOS Sierra/tdesktop 1.1.10

jimmy88 commented 7 years ago

I can reproduce this problem too on Ubuntu 16.04 (laptop)

smekras commented 7 years ago

I had the same problem here, i7 desktop, and a laptop, both with Fedora 25.

LiamDawe commented 7 years ago

I've noticed this too on Ubuntu, even more so when someone is typing a message/just posted it seems to spike up. Which is especially problematic when gaming.

carp3 commented 7 years ago

Same here. also lots of disk usage ... i7/laptop/Win10

kmare commented 7 years ago

Is there a way we could help the developers debug the issue? It seems like it's not OS or build specific..

stek29 commented 7 years ago

@kmare Is Sticker/GIF panel enabled? Is something playing? Are there any GIFs on screen? What if you defocus the app?

kmare commented 7 years ago

@stek29 No, the sticker/gif panel is hidden, nothing is playing, no gifs on scree. Moving the focus off the app won't help either. The only way to kill all these QThreads is to quit the app and restart it. So yeah, unfortunately I still haven't figured out what's causing the spawning of all these QThreads causing the high cpu load. At this moment, it looks so random as it could happen after a few minutes or a day.

silverfoxy commented 7 years ago

I was basically facing the same issue of high cpu load, as high as 140% on mac osx sierra with latest telegram desktop update (1.1.10 as of now) but I've had this issue on previous versions too, after digging for a little bit I found out that my local storage has caused an integer overflow (2244). screen shot 2017-07-19 at 11 46 54 pm And this is the local storage:

screen shot 2017-07-19 at 11 51 23 pm

After clearing the local storage now the issue seems to be fixed for me: screen shot 2017-07-20 at 12 00 34 am

kmare commented 7 years ago

@silverfoxy that's actually interesting. I checked my local storage and it seems fine though. So I guess, at least in my case, it has to be something else. Thank you for reporting that though!

kordestanchi commented 7 years ago

same problem in ubuntu 14.04 and 16.04. It starts to use a lot of cpu for no reason.

Yetangitu commented 7 years ago

Same here on Debian (Sid) 32bit on a Thinkpad T42p, Telegram takes more and more and more CPU after a (short) while. Tracing the process does not show much more than endless calls to clock_gettime, poll, recvmsg and futex:

[pid 32000] poll([{fd=6, events=POLLIN}, {fd=10, events=POLLIN}, {fd=12, events=POLLIN}, {fd=13, events=POLLIN}], 4, 399 <unfinished ...>
[pid 32031] clock_gettime(CLOCK_MONOTONIC, {tv_sec=451257, tv_nsec=102094921}) = 0
[pid 32031] poll([{fd=30, events=POLLIN}], 1, 0) = 0 (Timeout)
[pid 32031] clock_gettime(CLOCK_MONOTONIC, {tv_sec=451257, tv_nsec=112063820}) = 0
[pid 32031] poll([{fd=30, events=POLLIN}], 1, 0) = 0 (Timeout)
[pid 32031] clock_gettime(CLOCK_MONOTONIC, {tv_sec=451257, tv_nsec=112284246}) = 0
[pid 32031] clock_gettime(CLOCK_MONOTONIC, {tv_sec=451257, tv_nsec=112347384}) = 0
[pid 32031] clock_gettime(CLOCK_MONOTONIC, {tv_sec=451257, tv_nsec=112414434}) = 0
[pid 32031] clock_gettime(CLOCK_MONOTONIC, {tv_sec=451257, tv_nsec=112492100}) = 0
[pid 32031] poll([{fd=30, events=POLLIN}], 1, 30 <unfinished ...>
[pid 32030] <... poll resumed> )        = 0 (Timeout)
[pid 32030] clock_gettime(CLOCK_MONOTONIC, {tv_sec=451257, tv_nsec=115244212}) = 0
[pid 32030] clock_gettime(CLOCK_MONOTONIC, {tv_sec=451257, tv_nsec=115316570}) = 0
[pid 32030] clock_gettime(CLOCK_MONOTONIC, {tv_sec=451257, tv_nsec=115402338}) = 0
[pid 32030] write(6, "\1\0\0\0\0\0\0\0", 8) = 8
[pid 32000] <... poll resumed> )        = 1 ([{fd=6, revents=POLLIN}])
[pid 32030] clock_gettime(CLOCK_MONOTONIC,  <unfinished ...>
[pid 32000] read(6,  <unfinished ...>
[pid 32030] <... clock_gettime resumed> {tv_sec=451257, tv_nsec=115622205}) = 0
[pid 32000] <... read resumed> "\1\0\0\0\0\0\0\0", 16) = 8
[pid 32030] poll([{fd=31, events=POLLIN}], 1, 0 <unfinished ...>
[pid 32000] clock_gettime(CLOCK_MONOTONIC,  <unfinished ...>
[pid 32030] <... poll resumed> )        = 0 (Timeout)

This is a relatively recent problem, it started about a month ago. Earlier versions did not show this behaviour.

Yetangitu commented 7 years ago

I attached a running Telegram process to strace to see where things went berzerk. Telegram behaved nicely, 0.1% CPU, nothing special. Messed around a bit, nothing special.

Then I happened to move the pointer over that #%#¤&/%/%/ smiley button which I'd rather ditch yesterday than today. The blasted popup appeared again with a hoard of moving GIF images. I clicked outside of it to get rid of the dreaded things and had a look at the trace. 5 new threads had been launched and the trace was going wild, suddenly Telegram was hogging 25% CPU. Mind, the popup was gone, no moving images in sight, all peace and quiet on the surface. Below the surface it seems some QThreads were busy doing something anyway, something which took a lot of CPU.

Then I switched the horrible emjoistickergif popup to the 'emoji' tab and closed it. The CPU hoarding stopped. Switched back to the moving misery, closed popup, NO CPU HOARDING. Switched back and forth a few times, sometimes it started hoarding CPU, other times it didn't. The interesting observation is that I never got any hoarding problems when the popup was set to 'emoji' or 'stickers' but did get it when the thing was set to 'gifs'.

kmare commented 7 years ago

@Yetangitu thank you for "discovering" that! I'll take a look at that too and see if this is what is causing the 100% CPU load with telegram spawning all these QThreads.

kmare commented 7 years ago

I can confirm what @Yetangitu said! It really works! So basically, as soon as you see the CPU load going up cause of telegram, just click on the emoji/stickers/gifs icon once, click on it again and the telegram CPU load will go back to where it should be idling! If anyone else could confirm, please do so. Hopefully the developers will find a solution.

Yetangitu commented 7 years ago

From my observations it is enough to make sure that the popup is not set to 'gifs' before it is closed to avoid Telegram hogging the CPU. I have not seen any hogging since doing this.

sstyle commented 6 years ago

4238

sstyle commented 6 years ago

Same on High Sierra Mac OS, but 1.1.13alpha takes much less resources.

auchri commented 6 years ago

@sstyle Please try the current version, v1.2.6.

sstyle commented 6 years ago

@auchri I tried (you can see it here #4238) and found that 1.1.13 much better, but still has this issue.

pizzadude commented 6 years ago

This is just Telegram using your computers resources to create the first batch of TelegramCoin, the new cryptocurrency. Nothing to be worried about.

sstyle commented 6 years ago

@pizzadude Nice. So we can close this thread )

Hulkmaster commented 6 years ago

happened to me just now

steps to reproduce: launch high cpu (for a couple of minutes) low cpu wait a little bit high cpu (for a couple of minutes) low cpu

mac 10.13.3 telegram 1.2.6

i hope telegram didnt start using our PCs for Gram mining 🤔

davronakil commented 6 years ago

Same problem and I'm trying to fix it. Try turning off all notifications. So far I think it's not going crazy anymore.

durkmurder commented 6 years ago

I am using v1.2.6. What I saw that if telegram runs, CPU load is very high, it consumes 70% of CPU time. The only way to stop this is to minimize telegram window. If you just switch to other app, but leave it on screen, even if it's completely overlayed by another window, it won't help, only minimization helps.

Host OS: OS X 10.12.6

remybach commented 6 years ago

fwiw: I've particularly noticed this CPU issue when I've used the @gif bot. Even after selecting a gif and the popup has gone away the CPU sits at a really high percentage unless I quit and reopen.

john-preston commented 6 years ago

@remybach For me it goes down after the GIFs panel is closed :(

remybach commented 6 years ago

@john-preston The panel that's part of the popup when you hover over the emoji, or the popup when you search using the @gif bot? I never use the emoji one so I don't know about that one.

Annoyingly, I can't 100% reproduce this. I asked a friend and when he checked his CPU spiked up to 100%, but mine hardly blipped when I just tested.

john-preston commented 6 years ago

@remybach The GIFs kill the CPU in Telegram Desktop :( But when the popup hides (both the emoji-stickers-gifs and the inline bot results, like @gif one) it goes back for me.

Scukerman commented 6 years ago

In my case telegram starts consuming CPU in two cases:

  1. a chat has a message from @gif which is animated and is on screen (on page) right now.
  2. telegram starts playing a song from any music channel (e.g. https://t.me/ifletov).

100% reproducible.

OS: macOS 10.13.3 Telegram: 1.2.6

haodemon commented 6 years ago

I found that TelegramSwift (https://github.com/overtake/TelegramSwift) does not have this issue.

AntonMalyshev commented 6 years ago

TelegramSwift has low CPU load but is sluggish as hell, not better

diegogub commented 6 years ago

I have the same issue on telegram for OSX. High CPU usage after first chat..

ManuelSchneid3r commented 6 years ago

Yes. I am simply reading a group chat and my macbook glows. The chat does not allow media by the way. Only text.

ryush00 commented 6 years ago

After upgrade my Mac to High Sierra, CPU usage also got High.

tostr7191 commented 6 years ago

Version 1.2.6 on MacOS 10.13.3, same behaviour. Telegram suddenly starts using a lot of CPU for no apparent reason (no gif playing or anything). Restart of Telegram fixes the issue (until it occurs again). It's a recent issue (don't know the specific version, but it did not happen as of v1.0).

Etherealflux commented 6 years ago

I'm observing this behavior when I rapidly scroll through all of my gifs, then mouse away from the popup. My CPU usage spikes to at least 50% on my Ryzen 1700, and the app instantly eats a good 600 MB of memory.

Mousing over the gif menu, so that they briefly display again, fixes it immediately. Memory freed, CPU back to <1%

I have a number of very large MP4 files stored in there - think 1000x1000@60fps. That's probably exacerbating the issue.

It seems like Telegram is trying to render all of the videos at once, even though I'm not able to look at them, and just..getting stuck.

sstyle commented 6 years ago

Also I found that CPU load is very high when someone typing to me. Loading drops If he stops typing.

Shyotl commented 6 years ago

Still present with the latest release (1.2.17). The client (on windows 10 in this case) get stuck in an odd state where it seems to be processing the gifs tab even when not visible. Switching to the sticker or emoji tab resolves the issue. The issue is sporadic and I haven't found clean repro steps so far.

l1x commented 6 years ago
Also I found that CPU load is very high when someone typing to me. Loading drops If he stops typing.

Same here

tobsn commented 6 years ago

That's still a thing yes, latest OSX, latest TD... instant CPU spike, instant heat increase to 80C.

edit: with gifs/etc. hidden, just empty chat window with a lot of groups and private chats present but never opened, just starting the app and CPU will spike.

AntonMalyshev commented 6 years ago

Made me uninstall Telegram Desktop and use mobile version only

Yetangitu commented 6 years ago

All these symptoms - CPU hoarding on GIF, when someone is typing, etc - point at the culprit being something related to animations (tight loop running a timer?) as the typing... animation and all that moving-gif-misery share these characteristics. I haven't looked at the source yet, those who have might get an idea of where the problem lies. Maybe I should look at the source ...

...

Just looked at the source (https://github.com/telegramdesktop/tdesktop/blob/dev/Telegram/SourceFiles/ui/animation.h probably being the most interesting part), did not directly find anything pointing at tight loops so I did the next best thing: ask $search_engine. There seem to have been, and still seem to be a number of bugs in QT relating to high CPU load on animations. I notice that the binary served by Telegram is built with a static copy of Qt 5.6.2, current state of the art is 5.11. If anyone happens to have this installed and ready to build it might be worth comparing the result with the pre-baked version.

karray commented 6 years ago

the same here. win 10, telegram 1.2.17

after telegram runs for a while it starts to load cpu of about 10-15% and also when someone is typing or a gif play as already mentioned above

pryg-skok commented 6 years ago

Telegram desktop 1.2.24 alpha mac os high sierra (10.13.4) - client constantly uses more than 3% of CPU and has spikes to 10%. In IDLE state while I'm not even reading or chatting there.

I've attached sample of running application, maybe it could help telegram_samples.txt

JustM57 commented 6 years ago

TG for no reason starts to use 1850% of CPU. And I7-6950 Xtreme goes dead. But it really may happen because of GIF-bot as I started to use not long ago

benjaminmbrown commented 6 years ago

Y'all mining crypto in the background or something?

hmepas commented 6 years ago

Mac OS X 10.13.5 Telegram 1.3.9 Still an issue, out of the blue starts to eating cpu. Not even using emojis. Really annoying.

bonedaddy commented 6 years ago

Ubuntu 18.04 here, I've tried renicing all TG processes to 19 as well and that barely does anything :/

linjan commented 6 years ago

Same here :( d1288351 79c1108e