iOS Question Long Polling: bad performance in release mode

Discussion in 'iOS Questions' started by JanPRO, Jul 11, 2018.

  1. JanPRO

    JanPRO Well-Known Member Licensed User

    currently I am working on an App which uses Long Polling to update text in real time. I know, in many cases it's better to use WebSockets, however this discussion shouldn't be the topic of this thread.

    Here is my problem: In release mode the performance of the web requests is significant lower than in debug mode.
    I have created a small demo project which interacts with a WebApp and demonstrates the issue (I feel uncomfortable to publish it for everybody as it contains some backend information, so please write here or send me a PM). I have tested it on a real device (iPhone 5s) and made the following obversations: If I write text slowly at the WebApp, the text is exchanged nearly in real time. But at some point in release mode, the requests seem to "get stuck" and no data is received anymore.
    In which way code is executed differently in debug mode? I already have tried to run the requests in a background thread, but no success ...

    Any help?

  2. Sandman

    Sandman Well-Known Member Licensed User

    It seems to be a two dimensional matrix:
    - Compilation mode (debug/release)
    - Typing speed (slow/fast)

    For clarification, can you explain which combinations that work as expected and which ones that don't?
    JanPRO likes this.
  3. JanPRO

    JanPRO Well-Known Member Licensed User

    Typing slow & fast in debug mode works fine.
    Typing slow in release mode is ok but still not as good as fast typing in debug mode. Typing fast in release mode is a catastrophe, it seems that the code is somehow blocked in this case.

    Thank you.

  4. Erel

    Erel Administrator Staff Member Licensed User

    Don't do it. It will only cause problems.

    Are you sending a new request with every keystroke?
  5. JanPRO

    JanPRO Well-Known Member Licensed User

    On the server side, yes.
    The App sends a long polling request to the webapp with the hash of the last received text. The server compares the hash from the app with the latest hash of the text in the webapp and sends an update to the app if needed. Everytime the app gets an update or a timeout, it will reconnect to the server. Therefore one can indirect say, that also the App sends a new request with every keystroke.

  6. Erel

    Erel Administrator Staff Member Licensed User

    How are you keeping the connection alive?

    I don't see any reason for it to be slower in release mode. Maybe their is a timing problem somewhere.
  7. JanPRO

    JanPRO Well-Known Member Licensed User

    The execution time of the php scripts and the timeout of the request is increased.

  8. Erel

    Erel Administrator Staff Member Licensed User

    You should definitely try it with WebSockets or MQTT. It will be simpler and work better.

    One possible reason for it to be faster in debug mode is that in this mode the network is kept active all the time. This reduces the latency of network calls.
  9. sorex

    sorex Expert Licensed User

    I think the problem is similar to when doing an ajax based autocomplete in javascript/jquery.

    There I solve it with a key press timer that gets reset each time a key is pressed.

    If there's a 500+ms delay then only the call to the backend is done.

    If not things freeze due to the ajax/http calls and typing slows down.

    sockets are indeed kept open so the overhead is way less.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice