This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
elfin8er's profile picture

Eliminating HTTP Lag

Started by elfin8er, 17 March 2015 - 03:51 PM
elfin8er #1
Posted 17 March 2015 - 04:51 PM
I'm getting quite a bit of lag from my two computercraft programs. Both are constantly sending an HTTP request which I believe is the problem. While the programs are running, my game just freezes every so often. I don't just get bad FPS. The game actually freezes. I've also noticed this happen in the past with other programs that send many HTTP requests. Is there any workaround? I tried os.sleep(1) and even os.pullEvent() to no avail. Thanks everybody for the help!

Maybe spamming HTTP requests just isn't a good idea…
Lyqyd #2
Posted 17 March 2015 - 05:00 PM
It's not a good idea. What are you trying to do with all of those http requests?
MKlegoman357 #3
Posted 17 March 2015 - 05:01 PM
Spamming HTTP requests is actually not a good idea. What function do you use to send your requests? That's probably why the game freezes.
elfin8er #4
Posted 17 March 2015 - 06:09 PM
I've created a pretty advanced storage system with a web interface. I'm using OpenPeripherals to get the contents of an ME System, and send the data to my web server using a single request. This is on a constant loop so that the web server is always up to date. I guess I could optimize this by only sending a request whenever the contents of the ME System changes.

Then I have another computer constantly polling a text file that contains text when I need to send information to my computer. This is also on a constant loop so I can send information to the computer, from the web server whenever I need to. I'm not quite sure of any way to optimize this…

So is there just no work around for the sudden freezes? Also, if I built this on a server, would it freeze the server rather than the client?
Edited on 17 March 2015 - 05:11 PM
RoD #5
Posted 17 March 2015 - 07:32 PM
So you are sending tons of requests to your webserver? How often are the requests being sent? I mean you would send from 30 in 30 minutes. And i think only one request can't make the game freeze, so check if you are doing a lot of requests at the same time. I also recommend you to change the webserver code (is it in PHP?) and make it as simple as you can. Think that the less characters you send and receive the faster.
Bomb Bloke #6
Posted 17 March 2015 - 10:22 PM
I would also go with a timer-based system rather than a system that waits for changes. Once every five or ten minutes would be the minimum I'd go with.

Also bear in mind that you shouldn't be sending the complete content of the system unless you have to. For eg, if all that happened over the last X amount of time is that ten logs got added to the system, then the message you send should indicate "ten logs got added since the last update". It's excusable to send a complete inventory list when your script first starts, but until it restarts, subsequent updates should only cover what was altered.
elfin8er #7
Posted 18 March 2015 - 03:28 AM
I definitely think I can optimize the computer sending data to the server, but what about for the computer polling the server? I need to constantly poll it so the player doesn't have to wait. It'd be so nice if there was a way for a web browser to send data to a computer.

Also, at the moment, I'm constantly sending requests with no pause.
Edited on 18 March 2015 - 02:31 AM
Bomb Bloke #8
Posted 18 March 2015 - 06:02 AM
Sounds like you don't need to be gathering info from the server when no player is in front of the computer - perhaps rig up a time-out system so that if no user input is detected for a while, it stops.
elfin8er #9
Posted 19 March 2015 - 02:08 PM
Not sure what you're getting at exactly. I need to always be pinging the server, even if there isn't anybody near the computer. That's kind of the point of this storage system. I want it to be accessible from anywhere.
MKlegoman357 #10
Posted 19 March 2015 - 08:36 PM
You could send the data in 10-second or even 30-second intervals, unless those 30 seconds might be too slow (but I really doubt it). Also, only poll the server whenever the contents or whatever changes, there's no need to poll it when nothing happens. And like mentioned previously, only send data that has been changed, not everything.
RoD #11
Posted 19 March 2015 - 09:03 PM
Not sure what you're getting at exactly. I need to always be pinging the server, even if there isn't anybody near the computer. That's kind of the point of this storage system. I want it to be accessible from anywhere.

What kind of data are you sending to the server? Be precise please