ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf.pm
(Generate patch)

Comparing deliantra/server/lib/cf.pm (file contents):
Revision 1.365 by root, Tue Sep 11 13:27:56 2007 UTC vs.
Revision 1.372 by root, Sat Sep 15 13:25:33 2007 UTC

80our $NEXT_TICK; 80our $NEXT_TICK;
81our $NOW; 81our $NOW;
82our $USE_FSYNC = 1; # use fsync to write maps - default off 82our $USE_FSYNC = 1; # use fsync to write maps - default off
83 83
84our $BDB_POLL_WATCHER; 84our $BDB_POLL_WATCHER;
85our $BDB_DEADLOCK_WATCHER;
85our $BDB_CHECKPOINT_WATCHER; 86our $BDB_CHECKPOINT_WATCHER;
86our $BDB_TRICKLE_WATCHER; 87our $BDB_TRICKLE_WATCHER;
87our $DB_ENV; 88our $DB_ENV;
88 89
89our %CFG; 90our %CFG;
1352 aio_unlink +(playerdir $login) . "/$login.pl"; 1353 aio_unlink +(playerdir $login) . "/$login.pl";
1353 1354
1354 my $f = new_from_file cf::object::thawer path $login 1355 my $f = new_from_file cf::object::thawer path $login
1355 or return; 1356 or return;
1356 1357
1357 $f->next;
1358 my $pl = cf::player::load_pl $f 1358 my $pl = cf::player::load_pl $f
1359 or return; 1359 or return;
1360 local $cf::PLAYER_LOADING{$login} = $pl; 1360 local $cf::PLAYER_LOADING{$login} = $pl;
1361 $f->resolve_delayed_derefs; 1361 $f->resolve_delayed_derefs;
1362 $cf::PLAYER{$login} = $pl 1362 $cf::PLAYER{$login} = $pl
2462 (async { 2462 (async {
2463 # *tag paths override both path and x|y 2463 # *tag paths override both path and x|y
2464 if ($path =~ /^\*(.*)$/) { 2464 if ($path =~ /^\*(.*)$/) {
2465 if (my @obs = grep $_->map, ext::map_tags::find $1) { 2465 if (my @obs = grep $_->map, ext::map_tags::find $1) {
2466 my $ob = $obs[rand @obs]; 2466 my $ob = $obs[rand @obs];
2467
2468 # see if we actually can go there
2469 if (@obs = grep !$self->blocked ($_->map, $_->x, $_->y), $ob, $ob->tail) {
2470 $ob = $obs[rand @obs];
2471 } else {
2472 $self->message ("Wow, it's pretty crowded in there.", cf::NDI_UNIQUE | cf::NDI_RED);
2473 }
2474 # else put us there anyways for now #d#
2475
2467 ($path, $x, $y) = ($ob->map, $ob->x, $ob->y); 2476 ($path, $x, $y) = ($ob->map, $ob->x, $ob->y);
2477 } else {
2478 ($path, $x, $y) = (undef, undef, undef);
2468 } 2479 }
2469 } 2480 }
2470 2481
2471 my $map = eval { 2482 my $map = eval {
2472 my $map = cf::map::find $path; 2483 my $map = defined $path ? cf::map::find $path : undef;
2473 2484
2474 if ($map) { 2485 if ($map) {
2475 $map = $map->customise_for ($self); 2486 $map = $map->customise_for ($self);
2476 $map = $check->($map) if $check && $map; 2487 $map = $check->($map) if $check && $map;
2477 } else { 2488 } else {
2478 $self->message ("The exit to '$path' is closed", cf::NDI_UNIQUE | cf::NDI_RED); 2489 $self->message ("The exit to '$path' is closed.", cf::NDI_UNIQUE | cf::NDI_RED);
2479 } 2490 }
2480 2491
2481 $map 2492 $map
2482 }; 2493 };
2483 2494
3453 my $signal = new Coro::Signal; 3464 my $signal = new Coro::Signal;
3454 push @WAIT_FOR_TICK_BEGIN, $signal; 3465 push @WAIT_FOR_TICK_BEGIN, $signal;
3455 $signal->wait; 3466 $signal->wait;
3456} 3467}
3457 3468
3458our $stat_fh;
3459sysopen $stat_fh, "/tmp/cfstats", Fcntl::O_APPEND | Fcntl::O_CREAT | Fcntl::O_WRONLY, 0600;#d#
3460
3461$TICK_WATCHER = Event->timer ( 3469$TICK_WATCHER = Event->timer (
3462 reentrant => 0, 3470 reentrant => 0,
3463 parked => 1, 3471 parked => 1,
3464 prio => 0, 3472 prio => 0,
3465 at => $NEXT_TICK || $TICK, 3473 at => $NEXT_TICK || $TICK,
3469 Carp::cluck "major BUG: server tick called outside of main coro, skipping it" 3477 Carp::cluck "major BUG: server tick called outside of main coro, skipping it"
3470 unless ++$bug_warning > 10; 3478 unless ++$bug_warning > 10;
3471 return; 3479 return;
3472 } 3480 }
3473 3481
3474 my @pl = cf::player::list; my $stats = sprintf "%.2f %d %d %d", $RUNTIME, (scalar @pl), cf::object::actives_size, cf::object::objects_size; #d#
3475
3476 $NOW = $tick_start = Event::time; 3482 $NOW = $tick_start = Event::time;
3477 3483
3478 cf::server_tick; # one server iteration 3484 cf::server_tick; # one server iteration
3479 3485
3480 $RUNTIME += $TICK; 3486 $RUNTIME += $TICK;
3486 write_runtime 3492 write_runtime
3487 or warn "ERROR: unable to write runtime file: $!"; 3493 or warn "ERROR: unable to write runtime file: $!";
3488 }; 3494 };
3489 } 3495 }
3490 3496
3491# my $AFTER = Event::time;
3492# warn $AFTER - $NOW;#d#
3493
3494 if (my $sig = shift @WAIT_FOR_TICK_BEGIN) { 3497 if (my $sig = shift @WAIT_FOR_TICK_BEGIN) {
3495 $sig->send; 3498 $sig->send;
3496 } 3499 }
3497 while (my $sig = shift @WAIT_FOR_TICK) { 3500 while (my $sig = shift @WAIT_FOR_TICK) {
3498 $sig->send; 3501 $sig->send;
3508 3511
3509 $LOAD = ($NOW - $tick_start) / $TICK; 3512 $LOAD = ($NOW - $tick_start) / $TICK;
3510 $LOADAVG = $LOADAVG * 0.75 + $LOAD * 0.25; 3513 $LOADAVG = $LOADAVG * 0.75 + $LOAD * 0.25;
3511 3514
3512 _post_tick; 3515 _post_tick;
3513
3514 # gather some statistics#d#
3515 $stats .= sprintf " %d\n", 10000 * ($NOW - $tick_start);#d#
3516 IO::AIO::aio_write $stat_fh, undef, undef, $stats, 0;#d#
3517 }, 3516 },
3518); 3517);
3519 3518
3520{ 3519{
3521 BDB::min_parallel 8; 3520 BDB::min_parallel 8;
3544 ) 3543 )
3545 }; 3544 };
3546 3545
3547 unless ($DB_ENV) { 3546 unless ($DB_ENV) {
3548 $DB_ENV = BDB::db_env_create; 3547 $DB_ENV = BDB::db_env_create;
3548 $DB_ENV->set_flags (BDB::AUTO_COMMIT | BDB::REGION_INIT | BDB::TXN_NOSYNC
3549 | BDB::LOG_AUTOREMOVE, 1);
3550 $DB_ENV->set_timeout (30, BDB::SET_TXN_TIMEOUT);
3551 $DB_ENV->set_timeout (30, BDB::SET_LOCK_TIMEOUT);
3549 3552
3550 cf::sync_job { 3553 cf::sync_job {
3551 eval { 3554 eval {
3552 BDB::db_env_open 3555 BDB::db_env_open
3553 $DB_ENV, 3556 $DB_ENV,
3555 BDB::INIT_LOCK | BDB::INIT_LOG | BDB::INIT_MPOOL | BDB::INIT_TXN 3558 BDB::INIT_LOCK | BDB::INIT_LOG | BDB::INIT_MPOOL | BDB::INIT_TXN
3556 | BDB::RECOVER | BDB::REGISTER | BDB::USE_ENVIRON | BDB::CREATE, 3559 | BDB::RECOVER | BDB::REGISTER | BDB::USE_ENVIRON | BDB::CREATE,
3557 0666; 3560 0666;
3558 3561
3559 cf::cleanup "db_env_open($BDBDIR): $!" if $!; 3562 cf::cleanup "db_env_open($BDBDIR): $!" if $!;
3560
3561 $DB_ENV->set_flags (BDB::AUTO_COMMIT | BDB::REGION_INIT | BDB::TXN_NOSYNC
3562 | BDB::LOG_AUTOREMOVE, 1);
3563 $DB_ENV->set_lk_detect;
3564 }; 3563 };
3565 3564
3566 cf::cleanup "db_env_open(db): $@" if $@; 3565 cf::cleanup "db_env_open(db): $@" if $@;
3567 }; 3566 };
3568 } 3567 }
3569 3568
3569 $BDB_DEADLOCK_WATCHER = Event->timer (
3570 after => 3,
3571 interval => 1,
3572 hard => 1,
3573 prio => 0,
3574 data => WF_AUTOCANCEL,
3575 cb => sub {
3576 BDB::db_env_lock_detect $DB_ENV, 0, BDB::LOCK_DEFAULT, 0, sub { };
3577 },
3578 );
3570 $BDB_CHECKPOINT_WATCHER = Event->timer ( 3579 $BDB_CHECKPOINT_WATCHER = Event->timer (
3571 after => 11, 3580 after => 11,
3572 interval => 60, 3581 interval => 60,
3573 hard => 1, 3582 hard => 1,
3574 prio => 0, 3583 prio => 0,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines