remote AIs to spread CPU load

Programmers discuss here anything related to FreeOrion programming. Primarily for the developers to discuss.

Moderator: Committer

Post Reply
Message
Author
User avatar
Dilvish
AI Lead, Programmer
Posts: 4689
Joined: Sat Sep 22, 2012 6:25 pm

remote AIs to spread CPU load

#1 Post by Dilvish » Tue Apr 03, 2018 7:50 pm

(edit: split from here since this is developing into its own conversation.)
Ophiuchus wrote:@oleg For multiplayer, maybe we can make the AI serverless. Each AI would get its own virtual cpu in parallel and hopefully would be finished before any player is. We do not need cpu power waiting until everybody is finished, but if it is finished we need a lot. This would scale to any number of AI :)
(and doing it this way, maybe if someone like you is maintaining a server, you dont have to pay for the AI processing cost, but people could plug in their own processing power)
I rather suspect that is possible already; it is certainly possible in general to launch the AI processes separately from the regular client and server, though I don't recall if I have ever tested that out for a multiplayer game (and if I had it would have just been with a local server, in your case you'd need to specify the external server address as a command line option).
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

Ophiuchus
Vacuum Dragon
Posts: 510
Joined: Tue Sep 30, 2014 10:01 am

Re: Turn orders issue

#2 Post by Ophiuchus » Wed Apr 04, 2018 7:10 am

Dilvish wrote:
Ophiuchus wrote:@oleg For multiplayer, maybe we can make the AI serverless. Each AI would get its own virtual cpu in parallel and hopefully would be finished before any player is. We do not need cpu power waiting until everybody is finished, but if it is finished we need a lot. This would scale to any number of AI :)
(and doing it this way, maybe if someone like you is maintaining a server, you dont have to pay for the AI processing cost, but people could plug in their own processing power)
I rather suspect that is possible already; it is certainly possible in general to launch the AI processes separately from the regular client and server, though I don't recall if I have ever tested that out for a multiplayer game (and if I had it would have just been with a local server, in your case you'd need to specify the external server address as a command line option).
To clarify: With "Serverless" i meant to use serverless cloud computing like amazon lambda. So you give that "freeorion AI" lambda a workload (in our case a single AI turn) to compute and then it finishes. I was thinking of using gamestate as input and getting commands as result. Maybe also works with the AI fetching the state from server and sending commands like usual, but i didnt research until now.

I do not know how the AI process work. So I'll ask some more dump questions ;)
I imagine when the AI is started, the FOCS gets parsed like for a human client, then it connects to the server, fetches gamestate, calculates and sends sends orders to the server and waits for a signal from the server that there is new gamestate to process. Is that about right?

Is it possible to launch AI just to do a single turn? Does that have a lot of overhead (parsing etc)?
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

User avatar
Dilvish
AI Lead, Programmer
Posts: 4689
Joined: Sat Sep 22, 2012 6:25 pm

Re: Turn orders issue

#3 Post by Dilvish » Wed Apr 04, 2018 5:01 pm

Ophiuchus wrote:To clarify: With "Serverless" i meant to use serverless cloud computing like amazon lambda. So you give that "freeorion AI" lambda a workload (in our case a single AI turn) to compute and then it finishes. I was thinking of using gamestate as input and getting commands as result.
Ah. From "people could plug in their own processing power" I thought you meant the players running some extra AIs on their machines. And that's still what I'd urge you to look at to most readily accomplish the goal. The AI does not automatically package up and save its current state when it submits orders (although it does for saving the game and so depending on the autosave settings it might currently be doing that each turn).
Maybe also works with the AI fetching the state from server and sending commands like usual, but i didnt research until now.
Currently the AI is only provided an existing state at game load; for each turn it normally carries over its own state. Making it reload and refresh each turn would be a bit less efficient.
I do not know how the AI process work. So I'll ask some more dump questions ;)
I imagine when the AI is started, the FOCS gets parsed like for a human client, then it connects to the server, fetches gamestate, calculates and sends sends orders to the server and waits for a signal from the server that there is new gamestate to process. Is that about right?
About right, yes, a minor correction being simply that none of the state machines are really set up with the view that clients 'fetch' gamestate, they simply take when the server sends. That is perhaps largely a matter of semantics and interpretation of the various waiting states, but I think that trying to coordinate the AWS lambda launching of new AIs for every single turn would be way more hassle than it is worth.
Is it possible to launch AI just to do a single turn?
Currently, no, or only sort of-- the AI's are currently only told to quit when the game ends for whatever reason.
Does that have a lot of overhead (parsing etc)?
I do believe that this single-turn-AI proposal would add quite a fair bit of extra per-turn overhead. Next time you start up a game, pay attention to how long it takes the AIs to send their greetings to you-- that's pretty much how much extra overhead you'd be adding to every turn (and as the games progressed I think the per turn extra would increase a bit).
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

Morlic
AI Contributor
Posts: 238
Joined: Tue Feb 17, 2015 11:54 am

Re: Turn orders issue

#4 Post by Morlic » Wed Apr 04, 2018 5:53 pm

Dilvish wrote: I thought you meant the players running some extra AIs on their machines. And that's still what I'd urge you to look at to most readily accomplish the goal.
Which AI code is executed? Server sending arbitrary code to execute on client machine seems insane. Using the client's local AI code allows for easy and cheap cheats.
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

Ophiuchus
Vacuum Dragon
Posts: 510
Joined: Tue Sep 30, 2014 10:01 am

Re: Turn orders issue

#5 Post by Ophiuchus » Wed Apr 04, 2018 6:50 pm

Morlic wrote:
Dilvish wrote: I thought you meant the players running some extra AIs on their machines. And that's still what I'd urge you to look at to most readily accomplish the goal.
Which AI code is executed? Server sending arbitrary code to execute on client machine seems insane. Using the client's local AI code allows for easy and cheap cheats.
If you are concerned about cheating, "plugging-in" running the game on third party resources (like AWS) is probably the safer way to do. Anyway I would not be concerned that friends i play freeorion with would cheat that way. As far as i got it the server based multiplayer is also easily cheatable (logging in as somebody else).

And security-wise I dont think Dilvish meant arbitrary code execution, neither did I.
No matter if serverless or playerbased, you would deploy the matching freeorion version before "invoking".

Or does the gamestate include code?
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

User avatar
Dilvish
AI Lead, Programmer
Posts: 4689
Joined: Sat Sep 22, 2012 6:25 pm

Re: Turn orders issue

#6 Post by Dilvish » Wed Apr 04, 2018 6:52 pm

Morlic wrote:Which AI code is executed? Server sending arbitrary code to execute on client machine seems insane. Using the client's local AI code allows for easy and cheap cheats.
I was just promoting launching the AI's from command line as can be done now. That does raise a potential cheating situation as you note, so would probably only be really suitable for players who play together enough that they'd trust each other sufficiently that the benefits of more AIs outweighed their concerns about possible cheating.

I'm also not so sure that the potential cheating would really be 'easy and cheap'-- trying to modify the AI in some way that would give your empire a nontrivial benefit without it being noticeable to other players seems both tricky and at high risk of getting yourself banned. Flagging yourslef via a special empire name could be protected against by mandating empire names in some player-independent way. If the AI were crippled in some weird way that only you knew about, you'd still have to have some way to identify which AI it was, without that way being a deviation noticeable to the other players. Perhaps either direction of identification could be done via messaging, but if the players are going to have a rule (as the current multiplayer groups apparently do) about no alliances with AIs, then a GameRule could be added to enforce that by suppressing all communications to/from AIs (my recollection is that all such communications have to go through the server).

And wasn't there some checksum process put in place to also help check for local content modifications? That may have been geared only towards improving consistency/reliability rather than as a security feature, but it probably either does already create a further hurdle to cheating, or could be easily augmented to create a further hurdle.

So anyways, the cheating possibility is something to consider, but I think it could be reasonably managed much more easily than a remote-from-everyone single-turn AI.

Ophiuchus wrote:Or does the gamestate include code?
Not currently, no.
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

Morlic
AI Contributor
Posts: 238
Joined: Tue Feb 17, 2015 11:54 am

Re: Turn orders issue

#7 Post by Morlic » Wed Apr 04, 2018 8:36 pm

Dilvish wrote:If the AI were crippled in some weird way that only you knew about, you'd still have to have some way to identify which AI it was, without that way being a deviation noticeable to the other players. Perhaps either direction of identification could be done via messaging, but if the players are going to have a rule (as the current multiplayer groups apparently do) about no alliances with AIs, then a GameRule could be added to enforce that by suppressing all communications to/from AIs (my recollection is that all such communications have to go through the server).
Yeah... If only there was some way to communicate with a process on your own machine while having perfect access to its entire source code...

Come on, Dilvish :lol:
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

User avatar
Dilvish
AI Lead, Programmer
Posts: 4689
Joined: Sat Sep 22, 2012 6:25 pm

Re: Turn orders issue

#8 Post by Dilvish » Thu Apr 05, 2018 2:46 am

Morlic wrote:Yeah... If only there was some way to communicate with a process on your own machine while having perfect access to its entire source code... Come on, Dilvish :lol:
*facepalm*
OK, I don't know what happened there, I must have been distracted by a squirrel or something, repeatedly, lol.
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

User avatar
Oberlus
Vacuum Dragon
Posts: 669
Joined: Mon Apr 10, 2017 4:25 pm

Re: remote AIs to spread CPU load

#9 Post by Oberlus » Thu Apr 05, 2018 10:41 am

Squirrels may be truly evil :lol:

Regarding cheating issues, I would never trust anyone, ever. If there is a non-trust-based way to avoid/impede cheating, that is the way to go even if that implies bearable-but-worse game performance.
I was an active player of another community driven (yet not opensource due to cheating issues) game, SavageXR. Old friendships were irreparably broken due cheating. The ways to mess with the server were always very innovative (and quite often with the only purpose to screw the game for everyone in revenge for perceived offences). And they had systems to check the integrity/originality of the game clients.

Ophiuchus
Vacuum Dragon
Posts: 510
Joined: Tue Sep 30, 2014 10:01 am

Re: remote AIs to spread CPU load

#10 Post by Ophiuchus » Thu Apr 05, 2018 11:01 am

Oberlus wrote:If there is a non-trust-based way to avoid/impede cheating, that is the way to go even if that implies bearable-but-worse game performance. ...The ways to mess with the server were always very innovative (and quite often with the only purpose to screw the game for everyone in revenge for perceived offences). And they had systems to check the integrity/originality of the game clients.
I think that you already experienced there that securing is a barrel without a floor (does that idiom exist?)...
Freeorion wasnt build with security focus in mind, so i guess it would mean a huge effort to do anything meaningful.

Trust is one of the biggest complexity killers. So i wouldnt want any of those who could advance the game itself to spend resources on coding security against "immature players". I also have board gaming friends which have annoying playing habits. They are still friends, but i play board games with other people.
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Post Reply