0

I recently switched from a shared to dedicated host giving me alot more monitoring/control. I've been trying to debug an issue I've had since before I switched, very high memory usage. I think I've narrowed it down to a specific script that is a subscription to an instagram feed/api. It works in a codeIgniter framework.

This is a screenshot of my processes. Note the really high httpd memory values enter image description here

Here's my controller in codeIgniter

class Subscribe extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this->instagram_api->access_token = 'hidden';
    }
    function callback()
    {

    //echo anchor('logs/activity.log', 'LOG');
$min_id = ''; 
$next_min_id = '';      

$this->load->model('Subscribe_model');
$min_id = $this->Subscribe_model->min_id();

echo $min_id;

    $pugs = $this->instagram_api->tagsRecent('tagg','',$min_id);
    if($pugs){
    if (property_exists($pugs->pagination, 'min_tag_id')) {
            $next_min_id = $pugs->pagination->min_tag_id;
        }   
    foreach($pugs as $pug) {
        if(is_array($pug)) {     
            foreach($pug as $media) { 
                $url = $media->images->standard_resolution->url;
                $m_id = $media->id;
                $c_time = $media->created_time;
                $user = $media->user->username;
                $filter = $media->filter;
                $comments = $media->comments->count;
                $caption = $media->caption->text;
                $link = $media->link;
                $low_res=$media->images->low_resolution->url;
                $thumb=$media->images->thumbnail->url;
                $lat = $media->location->latitude;
                $long = $media->location->longitude;
                $loc_id = $media->location->id;
                $date = new DateTime('2000-01-01', new DateTimeZone('Pacific/Nauru'));

                $data = array(
                   'media_id' => $m_id,
                   'min_id' => $next_min_id,
                   'url' => $url, 
                   'c_time' => $c_time,
                   'user' => $user,
                   'filter' => $filter,
                   'comment_count' => $comments,
                   'caption' => $caption,
                   'link' => $link, 
                   'low_res' => $low_res,
                   'thumb' => $thumb,
                   'lat' => $lat,
                   'long' => $long,
                   'loc_id' => $loc_id,
                );
                $this->Subscribe_model->add_pug($data);

            }

        }

    }
    }

and here is the model....

class Subscribe_model extends CI_Model {

    function min_id(){

        $this->db->order_by("c_time", "desc");      
        $query = $this->db->get("pugs");

        if ($query->num_rows() > 0)
        {
           $row = $query->row(); 
           $min_id = $row->min_id;
           if(!$min_id){
            $min_id ='';
           }
        }   

        return $min_id;

    }

    function add_pug($data){

        $query = $this->db->get_where('pugs', array('media_id'=>$data['media_id']));
        if($query->num_rows() > 0){
            return FALSE;   
        }else{
            $this->db->insert('pugs', $data);   
        }

    }
}

//============================EDIT========================//

I've converted some of the services over to fast-cgi and it seems to have brought my memory usage down significantly but I've noticed a bump in CPU. I was hoping that switching to a dedicated server would have far less headaches and make things much easier but it's been a nightmare so far. Affraid I've bit off more than I can chew.

Another fear of mine is adding some more domain names to the server. Will that add a new process that will run real high like the multiple php-cgi's running in the last image?

Here's my most recent outputs... enter image description here enter image description here

4

1 回答 1

0

为确保没有真正的内存泄漏,请尝试只在服务器上运行 httpd/myslqd(killall Xorg / telinit 3),然后停止上述两个服务。记下free|grep Mem |sed 's/\([^0-9]*[^\ ]*\)\{3\}\([^\ ]*\).*/\1/'. 这是 X 个空闲字节的 RAM。现在,启动 httpd/mysqld 服务并让它们运行几百个请求。停止服务并再次记下数字,重复直到对中间结果满意。

httpd 消耗大量 RAM 的情况并不少见。mysqld 也缓存在内存中。这仅仅是因为,如果连续多次(连续)遇到相同的请求,则静态缓存已全部缓冲并且可以使用。

对于 PHP,一个类是预编译的,一旦系统在第一次编译后需要它,它就不必逐行解释脚本,它会有一个字节码编码的对象可以使用。如果 fstat.mtime > bytecode.mtime..

您可以使用以下命令分析非交换类型的实际内存使用情况:

ps -ylC httpd --sort:rss

提供静态文件的子进程大小约为 2-3M。对于PHP等动态内容,可能在15M左右

要配置 apache 如何设置工作程序,这些参数在 httpd.conf 中有效:

StartServers, 
MaxClients, 
MinSpareThreads, 
MaxSpareThreads, 
ThreadsPerChild, 
MaxRequestsPerChild 

检查此链接: http: //www.howtoforge.com/configuring_apache_for_maximum_performance

第 3.5 节:

MaxClients 设置服务器可以支持的最大同时请求的限制。产生的子进程数量不会超过这个数量。它不应该设置得太低,以至于新连接被放入队列中,最终超时并且服务器资源未被使用。将此设置得太高将导致服务器开始交换并且响应时间将急剧下降。MaxClients 的适当值可以计算为: MaxClients = Web 服务器专用的总 RAM / 最大子进程大小

Apache 性能调整可在此处获得http://httpd.apache.org/docs/2.0/misc/perf-tuning.html,请跳至有关进程创建的部分以获取有关上述配置选项的更多信息。

于 2012-06-18T03:58:37.570 回答