2016-12-12 11 views
-1

는 내가 3400 기계 흑연하는 데이터를 전송하는 니트,하지만 내 스크립트 내가최대 3400 대의 컴퓨터에서 스크립트를 빠르게 수행하는 방법은 무엇입니까?

def sendmsg(hostname,metric): 
     a = mntdir + hostname + '/' + metric + '_median' 
     with settings(hide('running'), warn_only=True): 
      valueMedian = local(("cat %s|grep %s|awk '{print $2}'") % (a,now),capture=True) 
      local(("echo %s.%s_Median_90days %s %s >/dev/udp/20.26.2.18/2001 ") % (hostname,metric,valueMedian,unixdate)) 


if __name__=='__main__': 
    while True: 
     localtime = time.asctime(time.localtime(time.time())) 
     date = datetime.datetime.now() 
     now1 = date.strftime("%H:%M") 
     print now1 
     now2 = date.strftime("%M") 
     with settings(hide('running'), warn_only=True): 
      unixdate = local("date +%s",capture=True) 
     if int(now2) % 5 == 0: 
      now = now1 + ':00' 
      p=Pool(100) 
      print now 
      for hostname in host: 
       for metric in metrics: 
        p.apply_async(sendmsg, args=(hostname,metric)) 
      starttime = time.asctime(time.localtime(time.time())) 
      print('Waiting for all job done...%s' % starttime) 
      p.close() 
      p.join() 
      stoptime = time.asctime(time.localtime(time.time())) 
      print('sending completed...%s ' % stoptime) 
     time.sleep(60) 
+0

* local * 기능은 무엇을 수행합니까? – volcano

답변

1
awk '/foo/ {print $2}' file 

이하는 아래의 코드를 감사, 3 개 또는 2 분을 줄일 수있는 방법, abount 완료하는 데 5 분 소요 대략 귀하와 동일합니다.

cat file | grep foo | awk '{print $2}' 

약간의 도움이 될 수있는 프로세스를 생성하지 마십시오.

+1

'grep foo file | ... '(쓸모없는 고양이 사용) –

+0

하하, 3 분 이상 줄었고, 다른 제안 사항은 2 분이면 훨씬 좋을 것입니다. – Flasking

+0

@KlausD. 바로 Ulrich가 추천 한 것입니다. ** **이 양식을 삭제 ** – volcano