按照网上的教程试着写了个asp web service,实现的是客户端每次请求往服务端写一条数据到数据库,可是测试下来,同时开5个客户端,每个客户端用循环写1000条数据(不设延时),发现5个客户端都写完居然要80来分种,感觉是太慢了,请问有什么办法能提高服务端的处理速度呢?

解决方案 »

  1.   

    楼上的就不用嘲笑他了。你的客户端是用xmlhttp还是服务器端的client?
      

  2.   

    按照网上的教程试着写了个web service用的socket?
      

  3.   

    Server端代码:
    <?php
    require_once("nusoap.php");
    $ns="http://bbox.mezimedia.com/blackbox3/google_Adwords/apility_1.0.0d/soap/nusoap";
    $server = new soap_server();
    $server->configureWSDL('LogService',$ns);
    $server->wsdl->schemaTargetNamespace=$ns;$server->register('log_debug',
                        array( 'timestamp' => 'xsd:string',
                               'module' => 'xsd:string',                        
                               'user'=>'xsd:string',
                               'operation'=>'xsd:string','message'=>'xsd:string',
                               'http_status_code'=>'xsd:string','refer_url'=>'xsd:string'
                              ),
                         array('success' => 'xsd:string'),
                         $ns
                       );
     
     function log_debug($timestamp,$module,$user,$operation,$message,$http_status_code='',$refer_url='')
     {
     
      $level="DEBUG";
     
        
        if(!ereg("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})",$timestamp,$regs)){
             
             return new soap_fault('Client','','Invalid log timestamp'); 
        
        }elseif(!($module=='M1'||$module=='M2'||$module=='M3'||$module=='M4'||$module=='M5')){
        
         return new soap_fault('Client','','Invalid log Module'); 
       
        }elseif(!((strcasecmp($operation, '1') == 0)||(strcasecmp($operation, '2') == 0)||strcasecmp($operation, '3') == 0)){
           
           return new soap_fault('Client','','Invalid log category'); 
        }
            
        elseif ($message==NULL || $message==' ')
        {
        
         return new soap_fault('Client','','message should not null'); 
        }
        elseif($user==NULL || $user==' '){
         return new soap_fault('Client','','user name should not null'); 
        }
        else{
           $fp=fopen("log_1020","a+");
           $anum=1020;
           
           $link = mysql_connect('web13', 'myuser', 'mypassword')
                       or die('Could not connect: ' . mysql_error());
         
            mysql_select_db('BBoxV3_ImportData') or die('Could not select database');
            
            $sql=" insert into log_message(level,timestamp,module,user,operation,message,http_status_code,referer_url) ";
            $sql.=" values('$level','$timestamp','$module','$user','$operation','$message','$http_status_code','$refer_url') ";
            
            $result = mysql_query($sql);
           
           if(!$result)        
    {
      echo $sql."\n";
              echo 'Query has error: ' . mysql_errno() . ':' . mysql_error() . '\n';
            mysql_close();
              exit;
           }   
           
           mysql_close();
           fwrite($fp,$timestamp."\t".$module."\t".$user."\t".$operation."\t".$level."\t".$message."\t".$http_status_code."\t".$refer_url."\n");
           fclose($fp);
           
          $str=$timestamp."\t".$module."\t".$user."\t".$operation."\t".$level."\t".$message."\t".$http_status_code."\t".$refer_url."\n";
       }    
           
     }
     
     $server->service($HTTP_RAW_POST_DATA);?>client:<?php
        include('nusoap.php'); 
        $wsdl="http://MyURL/server.php?wsdl"; 
        $client=new soapclient($wsdl, 'wsdl'); 
       
       $param=getparam(date("Y-m-d H:i:s"),'M5','guy','1','Here is some DEBUG');
       $result =  $client->call('log_debug', $param);
       
       echo $result."\n";
       echo "<xmp>".$client->request."</xmp>";
       echo "<xmp>".$client->response."</xmp>";
       
      // 用来转换成数组 
       function getparam($timestamp,$module,$user,$operation,$message,$http_status_code='',$refer_url='',$level='DEBUG')
       {
        $arr=array('timestamp'=>$timestamp,
                   'module'=>$module,
                   'level'=>$level,
                   'user'=>$user,
                   'operation'=>$operation,
                   'message'=>$message,
                   'http_status_code'=>$http_status_code,
                   'refer_url'=>$refer_url            
                  );
                  
          return $arr;
       
       }
    ?>恳请各位帮忙分析一下,多谢
      

  4.   

    我不是嘲笑他。只是开个玩笑。因为我觉得这帖迟早是要变成水帖的>:D。具体的时间xuzuning(唠叨) 已经写了。这个速度并不算慢。就算页面执行时间为0,打开一个页面总时间0.36也很正常。想更快的话可以考虑找个,或开发个不是用tcp协议的系统而不用web。
      

  5.   

    哦,并不算慢,多谢多谢。这么说来WEB service 并不是狠适合用来做这个东西
      

  6.   

    你比较过.net做的web service的速度吗?
    一定要切身比较过才好发表意见阿。
      

  7.   

    呵呵,唠叨老大好像算错了。
    呵呵5个同时,总共时间是30分钟。最后一个完成时,他自身总共用了30分钟。因此,对于他来说,平均每条记录耗时1.8秒可以在客户端、服务器端打印时间消耗出来看看,实际上,每次用php函数做数据库操作时的时间消耗都只是0.00xx秒,而在创建服务    $client=new soapclient($wsdl, 'wsdl');      和      远程调用方法   $result =  $client->call('log_debug', $param);
          时花去了大量时间,而如果你的客户端与服务器端都在一台机器上或者在局域网内,保障网络连接速度的话,那么每次的创建连接,调用也就是0.1x秒,这样的话,一次操作也就是0.3秒左右,而如果你创建一次连接,然后循环调用的话,那么平均每次操作时间在0.15秒左右。忽略多个socket连接,多数据库连接的影响的话需要的时间最小大概是
    2.5分钟。呵呵,不过,webservice并不适合    客户端特多, 操作特频繁的应用,建立连接花费时间太多(这个时间的花费主要是webservice实现自身的xml部分所影响,socket影响不大(嘿嘿,我自己瞎说的,随便看看就好,嘿嘿))。
      

  8.   

    偶马上要做一个这个东东。
    现在正在找资料。
    还要分析xml文档。