Commit 9519de18 authored by Ad Schellevis's avatar Ad Schellevis

Added profile option to check_reload_status (configd), measured framework...

Added profile option to check_reload_status (configd), measured framework overhead, current max processing for the daemon is about 6200 req/s on my macbook. ( limited by socket.accept, if needed we could implement another dispatch method in the future)

Simple implementation to use the backend service from the frontend implemented.
parent 4b16c753
......@@ -29,6 +29,7 @@
namespace OPNsense\Base;
use Phalcon\Mvc\Controller;
use Phalcon\Translate\Adapter\NativeArray;
/**
......@@ -39,14 +40,13 @@ class ControllerBase extends Controller
{
/**
* translate a text
* @param string $tag input text
* @return string
* @return NativeArray
*/
public function getTranslator()
{
// TODO: implement language service
$messages = array();
return new \Phalcon\Translate\Adapter\NativeArray(array(
return new NativeArray(array(
"content" => $messages
));
......
......@@ -32,12 +32,10 @@ namespace OPNsense\Base;
* Class IndexController
* @package OPNsense\Base
*/
class IndexController extends \OPNsense\Base\ControllerBase
class IndexController extends ControllerBase
{
public function indexAction()
{
// $this->view->title = $this->request->getURI();
// $this->view->pick('OPNsense/Sample/index');
}
}
......@@ -66,6 +66,7 @@ class PageController extends ControllerBase
/**
* controller for sample index page, defaults to http://<host>/sample/page
* @param array $error_msg error messages
*/
public function indexAction($error_msg = array())
{
......@@ -147,5 +148,6 @@ class PageController extends ControllerBase
"action" => "index"
));
return true;
}
}
......@@ -131,20 +131,24 @@ abstract class BaseModel
if ($config_section_data != null) {
$counter = 0 ;
foreach ($config_section_data as $conf_section) {
// iterate array items from config data
$child_node = new ContainerField($fieldObject->__reference . "." . ($counter++), $tagName);
$this->parseXml($xmlNode, $conf_section, $child_node);
$fieldObject->addChildNode(null, $child_node);
}
} else {
// There's no content in config.xml for this array node.
$child_node = new ContainerField($fieldObject->__reference . ".0", $tagName);
$child_node->setInternalIsVirtual();
$this->parseXml($xmlNode, $config_section_data, $child_node);
$fieldObject->addChildNode(null, $child_node);
}
} else {
// All other node types (Text,Email,...)
$this->parseXml($xmlNode, $config_section_data, $fieldObject);
}
// add object as child to this node
$internal_data->addChildNode($xmlNode->getName(), $fieldObject);
}
......
<?php
/**
* Copyright (C) 2015 Deciso B.V.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
namespace OPNsense\Core;
/**
* Class Backend
* @package OPNsense\Core
*/
class Backend
{
/**
* @var string location of configd socket
*/
private $configdSocket = "/Users/ad/Develop/deciso/opnsense/testing/check_reload_status";
// "/var/run/check_reload_status";
/**
* init Backend component
*/
public function __construct()
{
$this->stream = null;
}
/**
* send event to backend
* @param $event event string
* @param int $timeout timeout in seconds
* @return string
* @throws \Exception
*/
public function sendEvent($event, $timeout = 60)
{
$stream = stream_socket_client('unix://'.$this->configdSocket, $errorNumber, $errorMessage, $timeout);
if ($stream === false) {
throw new \Exception("Failed to connect: $errorMessage");
}
stream_set_timeout($stream, $timeout);
fwrite($stream, $event);
$resp = stream_get_contents($stream);
$info = stream_get_meta_data($stream);
if ($info['timed_out'] == 1) {
throw new \Exception("Timeout (".$timeout.") executing :".$event);
}
return $resp;
}
}
......@@ -42,7 +42,7 @@ import sys
import ConfigParser
import modules.processhandler
from modules.daemonize import Daemonize
import cProfile, pstats
# find program path
if len(__file__.split('/')[:-1]) >0 :
......@@ -73,7 +73,24 @@ else:
if len(sys.argv) > 1 and 'console' in sys.argv[1:]:
print('run %s in console mode'%sys.argv[0])
proc_handler.run()
if 'profile' in sys.argv[1:]:
# profile configd
# for graphical output use gprof2dot:
# gprof2dot -f pstats /tmp/configd.profile -o /tmp/callingGraph.dot
# (https://code.google.com/p/jrfonseca/wiki/Gprof2Dot)
print ("...<ctrl><c> to stop profiling")
profile = cProfile.Profile()
profile.enable()
try:
proc_handler.run()
except KeyboardInterrupt:
pass
except:
raise
profile.disable()
profile.dump_stats('/tmp/configd.profile')
else:
proc_handler.run()
else:
# daemonize process
daemon = Daemonize(app=__file__.split('/')[-1].split('.py')[0], pid=cnf.get('main','pid_filename'), action=proc_handler.run)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment