음
드문 경우지만, 네트웍 서버를 짜다가 packet 모두를 logging 하다보면(디버깅때문에) logging 의 시간이 중요해지는 경우가 있다. 실제로 큰 영향을 주는 일은 아니지만, 궁금해서 급조한 코드를 돌려봤다.
코드
#include "ace/OS.h" #include "ace/Log_Msg.h" #include "ace/Timeprobe_T.h" #include <string> #include <iostream> #include <fstream> using namespace std; const int LOGGING_COUNT = 300000; const char* LOG_STRING = "얼씨구절씨구지화자\n"; long long test_fstream(); long long test_systemcall(); long long test_ace(); int main(int argc, char* argv[]) { long long result; result = test_fstream(); cout << "test_fstream: " << result << endl; result = test_systemcall(); cout << "test_systemcall: " << result << endl; result = test_ace(); cout << "test_ace: " << result << endl; return 0; } long long test_fstream() { ACE_hrtime_t t = ACE_OS::gethrtime(); ofstream f("log.fstream"); for( int i = 0; i < LOGGING_COUNT; ++i ) f << LOG_STRING; return ACE_OS::gethrtime() - t; } long long test_systemcall() { ACE_hrtime_t t = ACE_OS::gethrtime(); int fd = open("log.systemcall", O_WRONLY|O_TRUNC|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); if( fd != -1 ) { for( int i = 0; i < LOGGING_COUNT; ++i ) write(fd, LOG_STRING, strlen(LOG_STRING)); } return ACE_OS::gethrtime() - t; } long long test_ace() { ACE_hrtime_t t = ACE_OS::gethrtime(); ACE_LOG_MSG->clr_flags(ACE_Log_Msg::STDERR); ACE_LOG_MSG->set_flags(ACE_Log_Msg::OSTREAM); ofstream f("log.ace"); ACE_LOG_MSG->msg_ostream(&f); for( int i = 0; i < LOGGING_COUNT; ++i ) ACE_DEBUG((LM_DEBUG,LOG_STRING)); return ACE_OS::gethrtime() - t; }- 참고
- 시간 측정을 위해서, ACE_Timeprobe 라는 놈이 있길래 써볼려고 했는데 실패했다. 나중에 다시 봐야지... 간단한 경우라면 ACE_OS::gethrtime 을 써도 충분할거다.
결과
yoonkn@nirvana 06.logging_performance]$ ./a.out test_fstream: 163073199 test_systemcall: 2102610020 test_ace: 9847295393 [yoonkn@nirvana 06.logging_performance]$ ./a.out test_fstream: 166386206 test_systemcall: 2156176995 test_ace: 10001876123 [yoonkn@nirvana 06.logging_performance]$ ./a.out test_fstream: 166666995 test_systemcall: 2152219564 test_ace: 9853144847
음 우라지게 느리군. 좀더 문서를 찾아서 I/O 를 효율적으로 하는 방법을 찾아봐야 겠구나.
