HTTP requests: Why does it lag?

You can talk about ManiaScript for ManiaPlanet here

Moderator: English Moderator

Post Reply
User avatar
BigBang1112
Posts: 389
Joined: 20 Jul 2015, 12:44
Location: Czech Republic
Contact:

HTTP requests: Why does it lag?

Post by BigBang1112 »

I won't go as big as the Map Editor API: Items and ghost blocks topic this time. :D

I've noticed some strange behavior when using the HTTP functions in CHttpManager while I was implementing playsessions into Challenge.

Calling a request creates a split second lag on the client. This is usually fine in the menu, but it really sucks when used in Solo script for example. Because when the request is called during the race, the lag in the middle of the race is created as well, interrupting the user experience. The lag intensity apparently depends also on user connection (in some way).

Also, from the evidence of other ManiaScripter, the lag also affect servers, so it's probably not a client-sided issue. Something seems to block the game loop.

Also, not sure if this is alright, but requests that take usually 30 milliseconds in internet browser, take like 130 when called in Maniaplanet (tested via Now variable). It's probably not wrong but may give an idea of why does it happen.

Little offtopic: Can anyone test the CreatePostFile function? I can't get it to work and it may not actually work. :?
Creator and competent racer. YouTube Discord
- ENVIMIX (out in open-source)
- Challenge (OUT NOW)
- Leaderboards (OUT NOW)
- Compute Shadows
User avatar
TMarc
Posts: 15441
Joined: 05 Apr 2011, 19:10
Location: Europe
Contact:

Re: HTTP requests: Why does it lag?

Post by TMarc »

The question is: why do you have to call http requests during a race? :?

Each separate request is always accompanied by lot of protocol (overhead) which results in this behavior.

If you want to get rid of the delay, then you need to either:
- setup a socket connection at the begin, keep it open and use it for requests
- use multithreading (not featured in maniascript as far as I assume)
- don't use in-between http requests at all
User avatar
BigBang1112
Posts: 389
Joined: 20 Jul 2015, 12:44
Location: Czech Republic
Contact:

Re: HTTP requests: Why does it lag?

Post by BigBang1112 »

TMarc wrote: 28 Nov 2019, 00:00 The question is: why do you have to call http requests during a race? :?

Each separate request is always accompanied by lot of protocol (overhead) which results in this behavior.

If you want to get rid of the delay, then you need to either:
- setup a socket connection at the begin, keep it open and use it for requests
- use multithreading (not featured in maniascript as far as I assume)
- don't use in-between http requests at all
There is a lot that can be requested during a race.

In Challenge, I made a thing I call playsessions which very basically creates a short-time HTTP communication service on a map you launch in solo. To send your gameplay information to the server, you have to request quite often, even during the race.
Additionally, and the major thing that requires during-race requesting, is the "status requesting" that I made which checks every 10 seconds about the title pack status, and for example, kick everyone from the title pack if a critical bug is found (I didn't implement title pack kicking yet due to lack of time), but this status requesting also checks how many people are playing your exact map and if new messages arrived in map chat, or if new notification has been received.
I also had the idea that when you pass a checkpoint, the race and checkpoint information would be sent to my web/database and I would be able to measure first-lap time and best-lap time records, which may be good to send in real-time? (or well, this could be actually sent after race I guess).

I unfortunately didn't know about long-polling when I was making these features and so it's a bit inefficient, but some of these things can't be done with long-polling anyway and you have to consistently send requests over and over again.

ManiaScript doesn't support sockets, only OpenPlanet does, which is what I want to avoid using in my "playful nontechnical" projects. We have only HTTP available, or we have to work around it through server controllers, tho that isn't really solo. xd

Multithreading in ManiaScript is kinda dream, but I mean, HTTP requests there work asynchronously, they don't block the game until the request has received response. They block the game for the actual split second and the game wakes up even if the request wasn't yet finished. The requests are processed in the background after calling Http.CreateGet() and the only way they are controllable is that you can Destroy them meanwhile they process. I'm not good at explaining this but this should make sense when you know about CHttpManager.
Creator and competent racer. YouTube Discord
- ENVIMIX (out in open-source)
- Challenge (OUT NOW)
- Leaderboards (OUT NOW)
- Compute Shadows
Post Reply

Return to “ManiaScript”

Who is online

Users browsing this forum: No registered users and 2 guests