<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div><span>thanks for the information. So disable fsync may not cause huge issue in logs, but will reduce the io wait.</span></div><div><span><br></span></div><div><span>Thanks</span></div><div><span>Damien</span></div><div><br></div>  <div style="font-size: 12pt; font-family: 'times new roman', 'new york', times, serif; "> <div style="font-size: 12pt; font-family: 'times new roman', 'new york', times, serif; "> <div dir="ltr"> <font size="2" face="Arial"> <hr size="1">  <b><span style="font-weight:bold;">From:</span></b> Michael Santos <michael.santos@gmail.com><br> <b><span style="font-weight: bold;">To:</span></b> Damienuk Davis <damienuk@ymail.com> <br><b><span style="font-weight: bold;">Cc:</span></b> Dmitry Kolesnikov <dmkolesnikov@gmail.com>; "erlang-questions@erlang.org"
 <erlang-questions@erlang.org> <br> <b><span style="font-weight: bold;">Sent:</span></b> Friday, July 27, 2012 6:04 PM<br> <b><span style="font-weight: bold;">Subject:</span></b> Re: [erlang-questions] run_erl and fsync<br> </font> </div> <br>
On Thu, Jul 26, 2012 at 09:27:56AM -0700, Damienuk Davis wrote:<br>> It's linux (Redhat ES 5.2) platform with following server configuration<br>> DL370 with 2*6core and 12GB RAM <br>> Is it safe to define O_SYNC (this will cause to bybass fsync call)?<br><br>According to the man page, fsync() will result in 2 writes (data + <br>mtime). So, O_SYNC should be faster.<br><br>> What can be the impact to the system?<br><br>Some of the log might be lost in a crash if sync writes are<br>disabled.<br><br>Here's an untested patch to run_erl that gives the option of disabling<br>sync writes. It'd be nice to add an option to use syslog too.<br><br>diff --git a/erts/etc/unix/run_erl.c b/erts/etc/unix/run_erl.c<br>index 6b350e8..e2de798 100644<br>--- a/erts/etc/unix/run_erl.c<br>+++ b/erts/etc/unix/run_erl.c<br>@@ -169,6 +169,7 @@ static int log_generations = DEFAULT_LOG_GENERATIONS;<br> static int log_maxsize     =
 DEFAULT_LOG_MAXSIZE;<br> static int log_alive_minutes = DEFAULT_LOG_ALIVE_MINUTES;<br> static int log_activity_minutes = DEFAULT_LOG_ACTIVITY_MINUTES;<br>+static int log_sync_on_write = 1;<br> static int log_alive_in_gmt = 0;<br> static char log_alive_format[ALIVE_BUFFSIZ+1];<br> static int run_daemon = 0;<br>@@ -296,6 +297,9 @@ int main(int argc, char **argv)<br>     if (log_maxsize < LOG_MIN_MAXSIZE)<br>       ERROR1(LOG_ERR,"Minimum RUN_ERL_LOG_MAXSIZE is %d", LOG_MIN_MAXSIZE);<br>   }<br>+  if ((p = getenv("RUN_ERL_DISABLE_SYNC_ON_WRITE"))) {<br>+    log_sync_on_write = 0;<br>+  }<br> <br>   /*<br>    * Create FIFOs and open them <br>@@ -480,6 +484,7 @@ static void pass_on(pid_t childpid)<br>     int maxfd;<br>     int ready;<br>     int got_some = 0; /* from to_erl */<br>+    int flags = O_RDWR|O_APPEND|O_CREAT;<br>     <br> 
    /* Open the to_erl pipe for reading.<br>      * We can't open the writing side because nobody is reading and <br>@@ -495,9 +500,11 @@ static void pass_on(pid_t childpid)<br> #endif<br>     <br>     /* Open the log file */<br>+    if (log_sync_on_write)<br>+        flags |= O_SYNC;<br>     <br>     lognum = find_next_log_num();<br>-    lfd = open_log(lognum, O_RDWR|O_APPEND|O_CREAT|O_SYNC);<br>+    lfd = open_log(lognum, flags);<br>     <br>     /* Enter the work loop */<br>     <br>@@ -842,7 +849,8 @@ static int open_log(int log_num, int flags)<br>       status("Error in writing to log.\n");<br> <br> #if USE_FSYNC<br>-  fsync(lfd);<br>+  if (log_sync_on_write)<br>+      fsync(lfd);<br> #endif<br> <br>   return lfd;<br>@@ -855,14 +863,19 @@ static int open_log(int
 log_num, int flags)<br> static void write_to_log(int* lfd, int* log_num, char* buf, int len)<br> {<br>   int size;<br>+  int flags = O_RDWR|O_CREAT|O_TRUNC|O_SYNC;<br> <br>   /* Decide if new logfile needed, and open if so */<br>   <br>   size = lseek(*lfd,0,SEEK_END);<br>   if(size+len > log_maxsize) {<br>+    if (!log_sync_on_write) {<br>+        fsync(*lfd);<br>+        flags &= ~O_SYNC;<br>+    }<br>     sf_close(*lfd);<br>     *log_num = next_log(*log_num);<br>-    *lfd = open_log(*log_num, O_RDWR|O_CREAT|O_TRUNC|O_SYNC); <br>+    *lfd = open_log(*log_num, flags);<br>   }<br> <br>   /* Write to log file */<br>@@ -872,7 +885,8 @@ static void write_to_log(int* lfd, int* log_num, char* buf, int len)<br>   }<br> <br> #if USE_FSYNC<br>-  fsync(*lfd);<br>+  if (log_sync_on_write)<br>+ 
   fsync(*lfd);<br> #endif<br> }<br> <br><br><br> </div> </div>  </div></body></html>