コード例 #1
0
 public function testCreate()
 {
     sleep(2);
     Kwf_Benchmark::enable();
     Kwf_Benchmark::reset();
     // sync with another instance
     $this->_getNewModel()->synchronize();
     $this->assertEquals(1, Kwf_Benchmark::getCounterValue('mirror sync'));
     Kwf_Benchmark::reset();
     // add a row to source model
     $source = $this->_sourceModel->createRow(array('id' => 4, 'firstname' => 'Vier', 'timefield' => date('Y-m-d H:i:s', time() - 5)));
     $source->save();
     $this->assertEquals(null, Kwf_Benchmark::getCounterValue('mirror sync'));
     $this->assertEquals(null, $this->_proxyModel->getRow(4));
     // update a row - at the end the added source row (id=4) must be in proxymodel
     $r = $this->_proxyModel->createRow();
     $r->firstname = 'Nadine';
     $r->timefield = date("Y-m-d H:i:s");
     $this->assertEquals(null, Kwf_Benchmark::getCounterValue('mirror sync'));
     $r->save();
     $this->assertEquals(1, Kwf_Benchmark::getCounterValue('mirror sync'));
     $this->assertEquals('Vier', $this->_proxyModel->getRow(4)->firstname);
     $this->assertEquals('Vier', $this->_mirrorModel->getRow(4)->firstname);
     $this->assertEquals(5, $r->id);
     $this->assertEquals(5, $this->_mirrorModel->getRow(5)->id);
     $this->assertEquals(5, $this->_sourceModel->getRow(5)->id);
     $this->assertEquals('Nadine', $this->_sourceModel->getRow(5)->firstname);
     Kwf_Benchmark::disable();
 }
コード例 #2
0
 public function indexAction()
 {
     Kwf_Benchmark::enable();
     Kwf_Benchmark::reset();
     self::setup();
     self::$proxyModel->countRows();
     echo (int) Kwf_Benchmark::getCounterValue('mirror sync');
     exit;
 }
コード例 #3
0
 public function testRequests()
 {
     Kwf_Benchmark::enable();
     Kwf_Benchmark::reset();
     $this->_proxyModel->getRows();
     $this->assertEquals(1, Kwf_Benchmark::getCounterValue('mirror sync'));
     $this->_proxyModel->getRow(3);
     $this->assertEquals(1, Kwf_Benchmark::getCounterValue('mirror sync'));
     $this->_proxyModel->getIds();
     $this->assertEquals(1, Kwf_Benchmark::getCounterValue('mirror sync'));
     $this->_proxyModel->countRows();
     $this->assertEquals(1, Kwf_Benchmark::getCounterValue('mirror sync'));
     Kwf_Benchmark::disable();
 }
コード例 #4
0
 public function testProcessInputPerformance()
 {
     Kwf_Benchmark::enable();
     Kwf_Benchmark::reset();
     $p = $this->_root->getChildComponent('_table1');
     $process = $p->getRecursiveChildComponents(array('page' => false, 'flags' => array('processInput' => true)));
     $process = array_values($process);
     $this->assertEquals(1, count($process));
     $this->assertEquals('root_table1-1-1', $process[0]->componentId);
     //Kwf_Benchmark::output();
     //root gibts schon
     //root_table, root_table-1, root_table-1-1
     $this->assertEquals(3, Kwf_Benchmark::getCounterValue('componentDatas'));
     Kwf_Benchmark::disable();
 }
コード例 #5
0
 public function testNoSyncWhenOnlySavedToSibling()
 {
     sleep(2);
     Kwf_Benchmark::enable();
     Kwf_Benchmark::reset();
     $mirror = new Kwf_Model_MirrorCache_MirrorCacheModel();
     $r = $mirror->getRow(1);
     $r->siblingcol = 'sib val 1';
     $r->save();
     $r = $mirror->getRow(1);
     $r->firstname = 'Herbert';
     $r->save();
     $this->assertEquals(1, Kwf_Benchmark::getCounterValue('mirror sync'));
     Kwf_Benchmark::reset();
     Kwf_Benchmark::disable();
     $this->assertEquals('sib val 1', $mirror->getRow(1)->siblingcol);
 }
コード例 #6
0
 public function testCached()
 {
     Kwf_Benchmark::enable();
     Kwf_Benchmark::reset();
     $d = Kwf_Registry::get('testDomain');
     $c = $this->_root->getPageByUrl("http://{$d}/foo", null);
     //uncached
     $this->assertEquals('1', $c->componentId);
     $this->assertEquals(1, Kwf_Benchmark::getCounterValue('componentDatas'));
     $this->assertEquals(0, (int) Kwf_Benchmark::getCounterValue('unserialized componentDatas'));
     Kwf_Component_Data_Root::reset();
     Kwf_Component_Data_Root::setComponentClass('Kwf_Component_Cache_UrlClearCache_Root');
     $this->_root = Kwf_Component_Data_Root::getInstance();
     Kwf_Benchmark::reset();
     $c = $this->_root->getPageByUrl("http://{$d}/foo", null);
     //cached
     $this->assertEquals('1', $c->componentId);
     $this->assertEquals(0, (int) Kwf_Benchmark::getCounterValue('componentDatas'));
     $this->assertEquals(1, Kwf_Benchmark::getCounterValue('unserialized componentDatas'));
 }
コード例 #7
0
 public function testSyncWithCli()
 {
     Kwf_Benchmark::enable();
     Kwf_Benchmark::reset();
     Kwf_Model_MirrorCache_TestController::setup();
     Kwf_Model_MirrorCache_TestController::$proxyModel->synchronize(Kwf_Model_MirrorCache::SYNC_ONCE);
     $this->assertEquals(1, (int) Kwf_Benchmark::getCounterValue('mirror sync'));
     $url = 'http://' . Kwf_Registry::get('testDomain') . '/kwf/test/kwf_model_mirror-cache_test';
     $this->assertEquals(0, file_get_contents($url));
     sleep(6);
     //sync delay ist 5 sec
     $this->assertEquals(1, file_get_contents($url));
     $this->assertEquals(0, file_get_contents($url));
     Kwf_Benchmark::reset();
     Kwf_Model_MirrorCache_TestController::$proxyModel->countRows();
     $this->assertEquals(0, (int) Kwf_Benchmark::getCounterValue('mirror sync'));
     sleep(6);
     //sync delay ist 5 sec
     Kwf_Benchmark::reset();
     Kwf_Model_MirrorCache_TestController::$proxyModel->synchronize(Kwf_Model_MirrorCache::SYNC_ALWAYS);
     $this->assertEquals(1, (int) Kwf_Benchmark::getCounterValue('mirror sync'));
     $this->assertEquals(0, file_get_contents($url));
 }
コード例 #8
0
 public function sendAction()
 {
     $this->_helper->viewRenderer->setNoRender(true);
     Kwf_Events_ModelObserver::getInstance()->disable();
     $newsletterId = $this->_getParam('newsletterId');
     $nlRow = Kwf_Model_Abstract::getInstance('Kwc_Newsletter_Model')->getRow($newsletterId);
     $mailsPerMinute = $nlRow->getCountOfMailsPerMinute();
     // In Schleife senden
     $queueLogModel = $nlRow->getModel()->getDependentModel('QueueLog');
     $count = 0;
     $countErrors = 0;
     $countNoUser = 0;
     $start = microtime(true);
     do {
         // Schlafen bis errechnet Zeit
         if ($nlRow->mails_per_minute != 'unlimited') {
             $sleep = $start + 60 / $mailsPerMinute * $count - microtime(true);
             if ($sleep > 0) {
                 usleep($sleep * 1000000);
             }
             if ($this->_getParam('debug')) {
                 echo "sleeping {$sleep}s\n";
             }
         }
         $nlStatus = Kwf_Model_Abstract::getInstance('Kwc_Newsletter_Model')->fetchColumnByPrimaryId('status', $nlRow->id);
         if ($nlStatus != 'sending') {
             if ($this->_getParam('debug')) {
                 echo "break sending because newsletter status changed to '{$nlStatus}'\n";
             }
             break;
         }
         Kwf_Benchmark::enable();
         Kwf_Benchmark::reset();
         Kwf_Benchmark::checkpoint('start');
         $userStart = microtime(true);
         // Zeile aus queue holen, falls nichts gefunden, Newsletter fertig
         $row = $nlRow->getNextQueueRow(getmypid());
         Kwf_Benchmark::checkpoint('get next recipient');
         if ($row) {
             $recipient = $row->getRecipient();
             if (!$recipient || !$recipient->getMailEmail()) {
                 $countNoUser++;
                 $status = 'usernotfound';
             } else {
                 if ($recipient instanceof Kwc_Mail_Recipient_UnsubscribableInterface && $recipient->getMailUnsubscribe()) {
                     $countNoUser++;
                     $status = 'usernotfound';
                 } else {
                     if ($recipient instanceof Kwf_Model_Row_Abstract && $recipient->hasColumn('activated') && !$recipient->activated) {
                         $countNoUser++;
                         $status = 'usernotfound';
                     } else {
                         try {
                             $mc = $nlRow->getMailComponent();
                             $t = microtime(true);
                             $mail = $mc->createMail($recipient);
                             $createTime = microtime(true) - $t;
                             $t = microtime(true);
                             $mail->send();
                             $sendTime = microtime(true) - $t;
                             Kwf_Benchmark::checkpoint('send mail');
                             $count++;
                             $status = 'sent';
                         } catch (Exception $e) {
                             echo 'Exception in Sending Newsletter with id ' . $nlRow->id . ' with recipient ' . $recipient->getMailEmail();
                             echo $e->__toString();
                             $countErrors++;
                             $status = 'failed';
                         }
                         $nlRow->getModel()->getTable()->update(array('count_sent' => new Zend_Db_Expr('count_sent + 1'), 'last_sent_date' => date('Y-m-d H:i:s')), 'id = ' . $nlRow->id);
                     }
                 }
             }
             $queueLogModel->createRow(array('newsletter_id' => $row->newsletter_id, 'recipient_model' => $row->recipient_model, 'recipient_id' => $row->recipient_id, 'status' => $status, 'send_date' => date('Y-m-d H:i:s')))->save();
             $row->delete();
             Kwf_Benchmark::checkpoint('update queue');
             if ($this->_getParam('verbose')) {
                 if (Kwf_Benchmark::isEnabled() && $this->_getParam('benchmark')) {
                     echo Kwf_Benchmark::getCheckpointOutput();
                 }
                 echo "[" . getmypid() . "] {$status} in " . round((microtime(true) - $userStart) * 1000) . "ms (";
                 echo "create " . round($createTime * 1000) . "ms, ";
                 echo "send " . round($sendTime * 1000) . "ms";
                 echo ") [" . round(memory_get_usage() / (1024 * 1024)) . "MB] [" . round($count / (microtime(true) - $start), 1) . " mails/s]\n";
             }
             if ($status == 'failed' && $this->_getParam('debug')) {
                 echo "stopping because sending failed in debug mode\n";
                 break;
             }
             if (memory_get_usage() > 100 * 1024 * 1024) {
                 if ($this->_getParam('debug')) {
                     echo "stopping because of >100MB memory usage\n";
                 }
                 break;
             }
         }
     } while ($row);
     $stop = microtime(true);
     // Log schreiben
     $logModel = $nlRow->getModel()->getDependentModel('Log');
     $row = $logModel->createRow(array('newsletter_id' => $nlRow->id, 'start' => date('Y-m-d H:i:s', floor($start)), 'stop' => date('Y-m-d H:i:s', floor($stop)), 'count' => $count, 'countErrors' => $countErrors));
     $row->save();
     // Debugmeldungen
     if ($this->_getParam('debug')) {
         $average = round($count / ($stop - $start) * 60);
         $info = $nlRow->getInfo();
         echo "\n";
         echo "{$count} Newsletters sent ({$average}/minute), {$countErrors} errors, {$countNoUser} user not found.\n";
         echo $info['text'] . "\n";
     }
     Kwf_Events_ModelObserver::getInstance()->enable();
 }
コード例 #9
0
 public function setUp()
 {
     parent::setUp('Kwf_Component_Generator_ChildPage_Root');
     Kwf_Benchmark::enable();
     Kwf_Benchmark::reset();
 }
コード例 #10
0
 public function testPerformance()
 {
     Kwf_Benchmark::enable();
     Kwf_Benchmark::reset();
     $m = new Kwf_Util_Model_Amazon_Products();
     $select = $m->select();
     $select->whereEquals('Keywords', 'php');
     $select->whereEquals('SearchIndex', 'Books');
     $select->limit(10);
     $m->getRows($select);
     $this->assertEquals(1, Kwf_Benchmark::getCounterValue('Service Amazon request'));
     $m->countRows($select);
     $this->assertEquals(1, Kwf_Benchmark::getCounterValue('Service Amazon request'));
     $select->limit(10, 10);
     $m->countRows($select);
     $this->assertEquals(1, Kwf_Benchmark::getCounterValue('Service Amazon request'));
     sleep(1);
     Kwf_Benchmark::reset();
     $m = new Kwf_Util_Model_Amazon_Products();
     $select->limit(10, 10);
     $m->getRows($select);
     $this->assertEquals(1, Kwf_Benchmark::getCounterValue('Service Amazon request'));
     $select->limit(10, 0);
     $m->countRows($select);
     $this->assertEquals(1, Kwf_Benchmark::getCounterValue('Service Amazon request'));
     Kwf_Benchmark::disable();
 }