… | |
… | |
6 | |
6 | |
7 | #our $DEACTIVATE_TIMEOUT = 20; # number of seconds after which maps get deactivated to save cpu |
7 | #our $DEACTIVATE_TIMEOUT = 20; # number of seconds after which maps get deactivated to save cpu |
8 | our $SWAP_TIMEOUT = 35; # number of seconds after which maps inactive get swapped out |
8 | our $SWAP_TIMEOUT = 35; # number of seconds after which maps inactive get swapped out |
9 | our $SCHEDULE_INTERVAL = 2; # time the map scheduler sleeps between runs |
9 | our $SCHEDULE_INTERVAL = 2; # time the map scheduler sleeps between runs |
10 | our $SAVE_TIMEOUT = 20; # save maps every n seconds |
10 | our $SAVE_TIMEOUT = 20; # save maps every n seconds |
|
|
11 | our $MAX_ACTIVES = $cf::CFG{max_actives} || 200000; # swap aggressively when > this many objects are active |
11 | |
12 | |
12 | cf::async_ext { |
13 | cf::async_ext { |
13 | $Coro::current->prio (Coro::PRIO_MIN); |
14 | $Coro::current->prio (Coro::PRIO_MIN); |
14 | # load the header of swapped-out maps. |
15 | # load the header of swapped-out maps. |
15 | # this is not a correctness issue, it simply saves diskspace |
16 | # this is not a correctness issue, it simply saves diskspace |
… | |
… | |
53 | # delete $map->{active}; |
54 | # delete $map->{active}; |
54 | # } |
55 | # } |
55 | if ($map->should_reset) { |
56 | if ($map->should_reset) { |
56 | $map->reset; |
57 | $map->reset; |
57 | } elsif ($map->in_memory == cf::MAP_IN_MEMORY) { |
58 | } elsif ($map->in_memory == cf::MAP_IN_MEMORY) { |
58 | if ($map->last_access + $SWAP_TIMEOUT <= $cf::RUNTIME && !$map->players) { |
59 | if ((cf::object::actives_size > $MAX_ACTIVES || $map->last_access + $SWAP_TIMEOUT <= $cf::RUNTIME) |
|
|
60 | && !$map->players) { |
|
|
61 | $map->swap_out; |
59 | $cf::WAIT_FOR_TICK_ONE->wait; |
62 | $cf::WAIT_FOR_TICK_ONE->wait; |
60 | $map->swap_out; |
|
|
61 | } elsif ($map->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { |
63 | } elsif ($map->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { |
|
|
64 | $map->save; |
62 | $cf::WAIT_FOR_TICK_ONE->wait; |
65 | $cf::WAIT_FOR_TICK_ONE->wait; |
63 | $map->save; |
|
|
64 | } |
66 | } |
65 | } |
67 | } |
66 | }; |
68 | }; |
67 | warn $@ if $@; |
69 | warn $@ if $@; |
68 | Coro::cede; |
70 | Coro::cede; |