hsahovic / poke-env

A python interface for training Reinforcement Learning bots to battle on pokemon showdown
https://poke-env.readthedocs.io/
MIT License
282 stars 93 forks source link

Memory Leak caused by ForfeitBattleOrder #244

Open BUCKFAE opened 2 years ago

BUCKFAE commented 2 years ago

Issue

I'm trying to create a Player that always instantly forfeits. I'm doing this because i want to generate all possible pokemon builds that appear in random battles. However my memory is slowly but steadily filling up when i run the example program below. Interestingly, once the python program has finished, the memory is not released until i manually shut down the local showdown server. This reaches 100% Memory usage eventually.

Minimal example to reproduce

Starting showdown:

➜  pokemon-showdown (master) cat ./start.sh
#!/bin/bash

./pokemon-showdown start --no-security
import asyncio

from poke_env.environment.abstract_battle import AbstractBattle
from poke_env.player.battle_order import BattleOrder, ForfeitBattleOrder
from poke_env.player.player import Player
from poke_env.player.random_player import RandomPlayer

class MinimalExample(Player):

    def choose_move(self, battle: AbstractBattle) -> BattleOrder:
        return ForfeitBattleOrder()

async def main():
    # Deleting old data dir

    p1 = MinimalExample(battle_format="gen8randombattle")
    p2 = RandomPlayer(battle_format="gen8randombattle")

    await p1.battle_against(p2, n_battles=60_000)

    print(f"RuleBased ({p1.n_won_battles} / {p2.n_won_battles}) Random")

if __name__ == "__main__":
    asyncio.get_event_loop().run_until_complete(main())

2021-12-08_16-12

My configuration

➜  pokemon-showdown (master) pip freeze | grep poke-env
poke-env==0.4.21
➜  pokemon-showdown (master) node --version
v14.18.1
➜  pokemon-showdown (master) npm --version
8.2.0
➜  pokemon-showdown (master) python --version
Python 3.9.9
➜  pokemon-showdown (master) neofetch
                   -`                    buckfae@bogen
                  .o+`                   -------------
                 `ooo/                   OS: Arch Linux x86_64
                `+oooo:                  Kernel: 5.15.6-arch2-1
               `+oooooo:                 Uptime: 50 mins
               -+oooooo+:                Packages: 1140 (pacman)
             `/:-:++oooo+:               Shell: bash 5.1.12
            `/++++/+++++++:              Resolution: 1920x1080, 1050x1680, 3840x2160
           `/++++++++++++++:             DE: GNOME 41.1
          `/+++ooooooooooooo/`           WM: Mutter
         ./ooosssso++osssssso+`          WM Theme: Adwaita
        .oossssso-````/ossssss+`         Theme: Adwaita [GTK2/3]
       -osssssso.      :ssssssso.        Icons: Adwaita [GTK2/3]
      :osssssss/        osssso+++.       Terminal: tmux
     /ossssssss/        +ssssooo/-       CPU: AMD Ryzen 7 3800X (16) @ 3.900GHz
   `/ossssso+/:-        -:/+osssso+-     GPU: NVIDIA GeForce RTX 3060 Lite Hash Rate
  `+sso+:-`                 `.-/+oso:    Memory: 6514MiB / 15962MiB
 `++:.                           `-/+/
 .`                                 `/
hsahovic commented 2 years ago

Hey @BUCKFAE,

Thanks for reaching out. I was able to reproduce what you observed. I started looking into potential causes, but haven't found a clear answer. I'll take a deeper look at it this week.

BUCKFAE commented 2 years ago

I just updated to python 3.10.1. The issue is still not resolved but it seems to have at least improved things a bit.