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.513 by root, Mon Apr 12 05:22:38 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
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 {
3584 3587
3585# install some emergency cleanup handlers 3588# install some emergency cleanup handlers
3586BEGIN { 3589BEGIN {
3587 our %SIGWATCHER = (); 3590 our %SIGWATCHER = ();
3588 for my $signal (qw(INT HUP TERM)) { 3591 for my $signal (qw(INT HUP TERM)) {
3589 $SIGWATCHER{$signal} = EV::signal $signal, sub { 3592 $SIGWATCHER{$signal} = AE::signal $signal, sub {
3590 cf::cleanup "SIG$signal"; 3593 cf::cleanup "SIG$signal";
3591 }; 3594 };
3592 } 3595 }
3593} 3596}
3594 3597
3595sub write_runtime_sync { 3598sub write_runtime_sync {
3596 my $t0 = EV::time; 3599 my $t0 = AE::time;
3597 3600
3598 # first touch the runtime file to show we are still running: 3601 # first touch the runtime file to show we are still running:
3599 # the fsync below can take a very very long time. 3602 # the fsync below can take a very very long time.
3600 3603
3601 IO::AIO::aio_utime $RUNTIMEFILE, undef, undef; 3604 IO::AIO::aio_utime $RUNTIMEFILE, undef, undef;
3623 or return; 3626 or return;
3624 3627
3625 aio_rename "$RUNTIMEFILE~", $RUNTIMEFILE 3628 aio_rename "$RUNTIMEFILE~", $RUNTIMEFILE
3626 and return; 3629 and return;
3627 3630
3628 warn sprintf "runtime file written (%gs).\n", EV::time - $t0; 3631 warn sprintf "runtime file written (%gs).\n", AE::time - $t0;
3629 3632
3630 1 3633 1
3631} 3634}
3632 3635
3633our $uuid_lock; 3636our $uuid_lock;
3771 return; 3774 return;
3772 } 3775 }
3773 3776
3774 return if $RELOAD++; 3777 return if $RELOAD++;
3775 3778
3776 my $t1 = EV::time; 3779 my $t1 = AE::time;
3777 3780
3778 while ($RELOAD) { 3781 while ($RELOAD) {
3779 warn "reloading..."; 3782 warn "reloading...";
3780 3783
3781 warn "entering sync_job"; 3784 warn "entering sync_job";
3884 3887
3885 warn "reloaded"; 3888 warn "reloaded";
3886 --$RELOAD; 3889 --$RELOAD;
3887 } 3890 }
3888 3891
3889 $t1 = EV::time - $t1; 3892 $t1 = AE::time - $t1;
3890 warn "reload completed in ${t1}s\n"; 3893 warn "reload completed in ${t1}s\n";
3891}; 3894};
3892 3895
3893our $RELOAD_WATCHER; # used only during reload 3896our $RELOAD_WATCHER; # used only during reload
3894 3897
3897 # coro crashes during coro_state_free->destroy here. 3900 # coro crashes during coro_state_free->destroy here.
3898 3901
3899 $RELOAD_WATCHER ||= cf::async { 3902 $RELOAD_WATCHER ||= cf::async {
3900 Coro::AIO::aio_wait cache_extensions; 3903 Coro::AIO::aio_wait cache_extensions;
3901 3904
3902 $RELOAD_WATCHER = EV::timer $TICK * 1.5, 0, sub { 3905 $RELOAD_WATCHER = AE::timer $TICK * 1.5, 0, sub {
3903 do_reload_perl; 3906 do_reload_perl;
3904 undef $RELOAD_WATCHER; 3907 undef $RELOAD_WATCHER;
3905 }; 3908 };
3906 }; 3909 };
3907} 3910}
3948 return; 3951 return;
3949 } 3952 }
3950 3953
3951 cf::server_tick; # one server iteration 3954 cf::server_tick; # one server iteration
3952 3955
3953 #for(1..3e6){} EV::now_update; $NOW=EV::now; # generate load #d# 3956 #for(1..3e6){} AE::now_update; $NOW=AE::now; # generate load #d#
3954 3957
3955 if ($NOW >= $NEXT_RUNTIME_WRITE) { 3958 if ($NOW >= $NEXT_RUNTIME_WRITE) {
3956 $NEXT_RUNTIME_WRITE = List::Util::max $NEXT_RUNTIME_WRITE + 10, $NOW + 5.; 3959 $NEXT_RUNTIME_WRITE = List::Util::max $NEXT_RUNTIME_WRITE + 10, $NOW + 5.;
3957 Coro::async_pool { 3960 Coro::async_pool {
3958 $Coro::current->{desc} = "runtime saver"; 3961 $Coro::current->{desc} = "runtime saver";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines