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

High CPU Usage when signed in to Xbox since 1.19.40 #775

Closed
GameParrot opened this issue Feb 2, 2023 · 13 comments
Closed

High CPU Usage when signed in to Xbox since 1.19.40 #775

GameParrot opened this issue Feb 2, 2023 · 13 comments
Labels
bug Something isn't working

Comments

@GameParrot
Copy link
Contributor

GameParrot commented Feb 2, 2023

Describe the bug
When signed in to Xbox live, the game uses way more CPU than it should.

To Reproduce
Steps to reproduce the behavior:

  1. Open the game
  2. Check CPU usage when signed out
  3. Sign in
  4. Check CPU usage again

Expected behavior
The CPU usage should not be super high when signed in.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Linux
  • Version 0.8.0
  • Installation Type Built from source. Also occurs with Appimage and Flatpak.

Additional context
The thread consuming CPU usage is REST Thread(0). strace shows a lot of EAGAIN (Resource temporarily unavailable) errors on the thread. This is likely related to the Microsoft account disconnected message that also started in 1.19.40 that is shown when in the pause menu of a singleplayer world.

@GameParrot GameParrot added the bug Something isn't working label Feb 2, 2023
@ChristopherHX
Copy link
Member

Maybe you need to implement the websocket java api in c++? It was recently added to the game, but I ignored it.

@GameParrot
Copy link
Contributor Author

Would stubbing the websocket functions resolve the high CPU usage?

@ChristopherHX
Copy link
Member

Probably not, websocket functions are already stubbed by automation.

strace shows a lot of EAGAIN (Resource temporarily unavailable) errors on the thread

Which libc function returns that error?
You could insert a sleep command into libc-shim if it returns EAGAIN and the thread will sleep instead of using your cpu time.
I have no idea and not even noticed the high cpu usage.

@GameParrot
Copy link
Contributor Author

It doesn't look like EAGAIN errors are coming through libc-shim, maybe they are being generated in the launcher's code, not the game's code

@GameParrot
Copy link
Contributor Author

GameParrot commented Feb 3, 2023

Also, reverting the async xbox http client fixes the cpu usage, but makes skins and marketplace not load. gdb also shows the write function failed crash that sometimes happens when closing the game occurring on the REST Thread(0).

@GameParrot
Copy link
Contributor Author

Maybe you need to implement the websocket java api in c++? It was recently added to the game, but I ignored it.

What WebSocket library should be used for something like this? I was able to fix the CPU usage issue by having it call onOpen when websocket connect is called, but nothing else. I stubbed the rest of the symbols for now.

@ChristopherHX
Copy link
Member

ChristopherHX commented Feb 6, 2023

You could use libcurl, it has expermental websocket support. I started trying to implement it, meanwhile I have more important things to do.

You could use the -DUSE_OWN_CURL=ON cmake flag (+ a flag to enable building websocket support, -DCURL_EXT_EXTRA_OPTIONS=-DENABLE_WEBSOCKETS=ON) to build a recent enough version from sources as part of the build, used by 32bit mcpelauncher-client32 on the AppImage. This wouldn't add any completly new dependency, but the build system needs to be changed to use that flag.

@GameParrot
Copy link
Contributor Author

Where can I find a websocket example program using libcurl? I can't seem to find one.

@ChristopherHX
Copy link
Member

That's true it is hard to find examples at this time.
You can find websocket tests in the curl sourcecode, they show how to use it.

@GameParrot
Copy link
Contributor Author

I started trying to implement it, meanwhile I have more important things to do.

Can you put what you have in a new branch?

@ChristopherHX
Copy link
Member

I don't have much, nothing I ever tested. It seems to be important to handle text and binary messages differently.

    // auto m = curl_ws_meta(nullptr);
    // if(m->flags & CURLWS_BINARY) {
        
    // }

    // curl_easy_setopt(curl, CURLOPT_URL, URL);

    // /* use the callback style */
    // curl_easy_setopt(curl, CURLOPT_USERAGENT, "webbie-sox/3");
    // curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
    // curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writecb);
    // curl_easy_setopt(curl, CURLOPT_WRITEDATA, curl);
    // res = curl_easy_perform(curl);

Seems like I altered ext/curl.cmake

ExternalProject_Add(
        curl_ext
        URL "http://curl.haxx.se/download/curl-7.87.0.tar.gz"
        INSTALL_DIR ${CMAKE_BINARY_DIR}/ext/curl
        CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/ext/curl" "-DBUILD_CURL_EXE=OFF" "-DBUILD_SHARED_LIBS=OFF" "-DCURL_STATICLIB=ON" "-DCURL_DISABLE_LDAP=ON" "-DCMAKE_USE_LIBSSH2=OFF" "-DCMAKE_USE_OPENLDAP=OFF" "-DUSE_LIBIDN2=OFF" "-DENABLE_WEBSOCKETS=ON" "-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}" "-DCMAKE_LINK_FLAGS=${CMAKE_LINK_FLAGS}" "-DCMAKE_LIBRARY_ARCHITECTURE=${CMAKE_LIBRARY_ARCHITECTURE}" ${CURL_EXT_EXTRA_OPTIONS}
)

But CURL_EXT_EXTRA_OPTIONS should also work.

I would use a writecb to call the message received java callbacks.

Trust me that mostly nothing.

@GameParrot
Copy link
Contributor Author

I put a temporary fix for the CPU usage that can be used until websocket support is added at minecraft-linux/mcpelauncher-client#42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants