Showing posts with label My Indexs. Show all posts
Showing posts with label My Indexs. Show all posts

11 December, 2009

The fastest way to get time in millisecond on linux

"gettimeofday()" is a great function to get time in millisecond.

Sample usage:
struct timeval start, end;
gettimeofday(&start, NULL);
usleep(2000);
gettimeofday(&end, NULL);

printf("%ld milliseconds\n", ((end.tv_sec-start.tv_sec) * 1000 + (end.tv_usec-start.tv_usec)/1000.0));

Moreover, we can even speed up this function!
According to this post, we can enable Virtual Dynamic Shared Object to speed things up.
# echo 2 > /proc/sys/kernel/vsyscall64


25 November, 2009

FastCGI: non-blocking FCGI_Accept_r

1. FCGX_InitRequest(&request, 0, FCGI_FAIL_ACCEPT_ON_INTR)
2.
int flags = fcntl(0, F_GETFL, 0);
fcntl(0, F_SETFL, flags | O_NONBLOCK);
3. sigaction


"We intentionally try to set the SA_RESTART flag for all signals other than SIGALRM, so that any system call interrupted by these other signals is automatically restarted. The reason we don't want SIGALRM restarted is to allow us to set a timeout for I/O operations."

18 November, 2009

12 November, 2009

Terms to remember

C++ exception safe:
Copy-and-Swap trick