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.511 by root, Wed Apr 7 18:35:56 2010 UTC vs.
Revision 1.516 by root, Thu Apr 15 06:05:52 2010 UTC

108our $PIDFILE = "$LOCALDIR/pid"; 108our $PIDFILE = "$LOCALDIR/pid";
109our $RUNTIMEFILE = "$LOCALDIR/runtime"; 109our $RUNTIMEFILE = "$LOCALDIR/runtime";
110 110
111our %RESOURCE; 111our %RESOURCE;
112 112
113our $OUTPUT_RATE_MIN = 4000;
114our $OUTPUT_RATE_MAX = 100000;
115
113our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!) 116our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!)
114our $NEXT_RUNTIME_WRITE; # when should the runtime file be written 117our $NEXT_RUNTIME_WRITE; # when should the runtime file be written
115our $NEXT_TICK; 118our $NEXT_TICK;
116our $USE_FSYNC = 1; # use fsync to write maps - default on 119our $USE_FSYNC = 1; # use fsync to write maps - default on
117 120
396} 399}
397 400
398=item cf::periodic $interval, $cb 401=item cf::periodic $interval, $cb
399 402
400Like EV::periodic, but randomly selects a starting point so that the actions 403Like EV::periodic, but randomly selects a starting point so that the actions
401get spread over timer. 404get spread over time.
402 405
403=cut 406=cut
404 407
405sub periodic($$) { 408sub periodic($$) {
406 my ($interval, $cb) = @_; 409 my ($interval, $cb) = @_;
503 506
504sub sync_job(&) { 507sub sync_job(&) {
505 my ($job) = @_; 508 my ($job) = @_;
506 509
507 if ($Coro::current == $Coro::main) { 510 if ($Coro::current == $Coro::main) {
508 my $time = EV::time; 511 my $time = AE::time;
509 512
510 # this is the main coro, too bad, we have to block 513 # this is the main coro, too bad, we have to block
511 # till the operation succeeds, freezing the server :/ 514 # till the operation succeeds, freezing the server :/
512 515
513 LOG llevError, Carp::longmess "sync job";#d# 516 LOG llevError, Carp::longmess "sync job";#d#
530 } else { 533 } else {
531 EV::loop EV::LOOP_ONESHOT; 534 EV::loop EV::LOOP_ONESHOT;
532 } 535 }
533 } 536 }
534 537
535 my $time = EV::time - $time; 538 my $time = AE::time - $time;
536 539
537 $TICK_START += $time; # do not account sync jobs to server load 540 $TICK_START += $time; # do not account sync jobs to server load
538 541
539 wantarray ? @res : $res[0] 542 wantarray ? @res : $res[0]
540 } else { 543 } else {
584 reset_signals; 587 reset_signals;
585 &$cb 588 &$cb
586 }, @args; 589 }, @args;
587 590
588 wantarray ? @res : $res[-1] 591 wantarray ? @res : $res[-1]
592}
593
594sub objinfo {
595 (
596 "counter value" => cf::object::object_count,
597 "objects created" => cf::object::create_count,
598 "objects destroyed" => cf::object::destroy_count,
599 "freelist size" => cf::object::free_count,
600 "allocated objects" => cf::object::objects_size,
601 "active objects" => cf::object::actives_size,
602 )
589} 603}
590 604
591=item $coin = coin_from_name $name 605=item $coin = coin_from_name $name
592 606
593=cut 607=cut
3529 LOG llevInfo, "Welcome to Deliantra, v" . VERSION; 3543 LOG llevInfo, "Welcome to Deliantra, v" . VERSION;
3530 LOG llevInfo, "Copyright (C) 2005-2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team."; 3544 LOG llevInfo, "Copyright (C) 2005-2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team.";
3531 LOG llevInfo, "Copyright (C) 1994 Mark Wedel."; 3545 LOG llevInfo, "Copyright (C) 1994 Mark Wedel.";
3532 LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen."; 3546 LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen.";
3533 3547
3534 cf::init_experience;
3535 cf::init_anim;
3536 cf::init_attackmess;
3537 cf::init_dynamic;
3538
3539 $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority 3548 $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority
3540 3549
3541 # we must not ever block the main coroutine 3550 # we must not ever block the main coroutine
3542 local $Coro::idle = sub { 3551 local $Coro::idle = sub {
3543 Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d# 3552 Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d#
3548 }; 3557 };
3549 3558
3550 evthread_start IO::AIO::poll_fileno; 3559 evthread_start IO::AIO::poll_fileno;
3551 3560
3552 cf::sync_job { 3561 cf::sync_job {
3562 cf::init_experience;
3563 cf::init_anim;
3564 cf::init_attackmess;
3565 cf::init_dynamic;
3566
3553 cf::load_settings; 3567 cf::load_settings;
3554 cf::load_materials; 3568 cf::load_materials;
3555 3569
3556 reload_resources; 3570 reload_resources;
3557 reload_config; 3571 reload_config;
3573 use POSIX (); 3587 use POSIX ();
3574 POSIX::close delete $ENV{LOCKUTIL_LOCK_FD} if exists $ENV{LOCKUTIL_LOCK_FD}; 3588 POSIX::close delete $ENV{LOCKUTIL_LOCK_FD} if exists $ENV{LOCKUTIL_LOCK_FD};
3575 3589
3576 (pop @POST_INIT)->(0) while @POST_INIT; 3590 (pop @POST_INIT)->(0) while @POST_INIT;
3577 }; 3591 };
3592
3593 cf::object::thawer::errors_are_fatal 0;
3578 3594
3579 main_loop; 3595 main_loop;
3580} 3596}
3581 3597
3582############################################################################# 3598#############################################################################
3584 3600
3585# install some emergency cleanup handlers 3601# install some emergency cleanup handlers
3586BEGIN { 3602BEGIN {
3587 our %SIGWATCHER = (); 3603 our %SIGWATCHER = ();
3588 for my $signal (qw(INT HUP TERM)) { 3604 for my $signal (qw(INT HUP TERM)) {
3589 $SIGWATCHER{$signal} = EV::signal $signal, sub { 3605 $SIGWATCHER{$signal} = AE::signal $signal, sub {
3590 cf::cleanup "SIG$signal"; 3606 cf::cleanup "SIG$signal";
3591 }; 3607 };
3592 } 3608 }
3593} 3609}
3594 3610
3595sub write_runtime_sync { 3611sub write_runtime_sync {
3596 my $t0 = EV::time; 3612 my $t0 = AE::time;
3597 3613
3598 # first touch the runtime file to show we are still running: 3614 # first touch the runtime file to show we are still running:
3599 # the fsync below can take a very very long time. 3615 # the fsync below can take a very very long time.
3600 3616
3601 IO::AIO::aio_utime $RUNTIMEFILE, undef, undef; 3617 IO::AIO::aio_utime $RUNTIMEFILE, undef, undef;
3623 or return; 3639 or return;
3624 3640
3625 aio_rename "$RUNTIMEFILE~", $RUNTIMEFILE 3641 aio_rename "$RUNTIMEFILE~", $RUNTIMEFILE
3626 and return; 3642 and return;
3627 3643
3628 warn sprintf "runtime file written (%gs).\n", EV::time - $t0; 3644 warn sprintf "runtime file written (%gs).\n", AE::time - $t0;
3629 3645
3630 1 3646 1
3631} 3647}
3632 3648
3633our $uuid_lock; 3649our $uuid_lock;
3771 return; 3787 return;
3772 } 3788 }
3773 3789
3774 return if $RELOAD++; 3790 return if $RELOAD++;
3775 3791
3776 my $t1 = EV::time; 3792 my $t1 = AE::time;
3777 3793
3778 while ($RELOAD) { 3794 while ($RELOAD) {
3779 warn "reloading..."; 3795 warn "reloading...";
3780 3796
3781 warn "entering sync_job"; 3797 warn "entering sync_job";
3884 3900
3885 warn "reloaded"; 3901 warn "reloaded";
3886 --$RELOAD; 3902 --$RELOAD;
3887 } 3903 }
3888 3904
3889 $t1 = EV::time - $t1; 3905 $t1 = AE::time - $t1;
3890 warn "reload completed in ${t1}s\n"; 3906 warn "reload completed in ${t1}s\n";
3891}; 3907};
3892 3908
3893our $RELOAD_WATCHER; # used only during reload 3909our $RELOAD_WATCHER; # used only during reload
3894 3910
3897 # coro crashes during coro_state_free->destroy here. 3913 # coro crashes during coro_state_free->destroy here.
3898 3914
3899 $RELOAD_WATCHER ||= cf::async { 3915 $RELOAD_WATCHER ||= cf::async {
3900 Coro::AIO::aio_wait cache_extensions; 3916 Coro::AIO::aio_wait cache_extensions;
3901 3917
3902 $RELOAD_WATCHER = EV::timer $TICK * 1.5, 0, sub { 3918 $RELOAD_WATCHER = AE::timer $TICK * 1.5, 0, sub {
3903 do_reload_perl; 3919 do_reload_perl;
3904 undef $RELOAD_WATCHER; 3920 undef $RELOAD_WATCHER;
3905 }; 3921 };
3906 }; 3922 };
3907} 3923}
3948 return; 3964 return;
3949 } 3965 }
3950 3966
3951 cf::server_tick; # one server iteration 3967 cf::server_tick; # one server iteration
3952 3968
3953 #for(1..3e6){} EV::now_update; $NOW=EV::now; # generate load #d# 3969 #for(1..3e6){} AE::now_update; $NOW=AE::now; # generate load #d#
3954 3970
3955 if ($NOW >= $NEXT_RUNTIME_WRITE) { 3971 if ($NOW >= $NEXT_RUNTIME_WRITE) {
3956 $NEXT_RUNTIME_WRITE = List::Util::max $NEXT_RUNTIME_WRITE + 10, $NOW + 5.; 3972 $NEXT_RUNTIME_WRITE = List::Util::max $NEXT_RUNTIME_WRITE + 10, $NOW + 5.;
3957 Coro::async_pool { 3973 Coro::async_pool {
3958 $Coro::current->{desc} = "runtime saver"; 3974 $Coro::current->{desc} = "runtime saver";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines