[erlang-questions] run_erl and fsync

Damienuk Davis <>
Thu Jul 26 14:36:35 CEST 2012

In my project there are fsms that communicates with c via erl driver (port). There are io:fwrite's in the erlang side. This program along works fine. But when you run some other process with high disk access, it causes erlang program to halt even if there is enough memory and processing. If I comment the fsync is run_erl.c file then program works fine even with higher load on hard disk. 
static void write_to_log(int* lfd, int* log_num, char* buf, int len)
  int size;

  /* Decide if new logfile needed, and open if so */

  size = lseek(*lfd,0,SEEK_END);
  if(size+len > log_maxsize) {
    *log_num = next_log(*log_num);
    *lfd = open_log(*log_num, O_RDWR|O_CREAT|O_TRUNC|O_SYNC);

  /* Write to log file */

  if (write_all(*lfd, buf, len) < 0) {
    status("Error in writing to log.\n");

  fsync(*lfd);//after commenting this line it works fine 


 From: dmitry kolesnikov <>
To: Damienuk Davis <> 
Cc: "" <> 
Sent: Thursday, July 26, 2012 5:44 PM
Subject: Re: [erlang-questions] run_erl and fsync

Does fsync block any VM scheduler? Or is it executed within async thread?
Or none of them :-)

I do not think that flush log is required for majority of Web systems. I believe this is a TeleCo legacy... Should it be configurable at least build time?

Best Regards,
Dmitry >-|-|-*>

On 26.7.2012, at 9.10, Damienuk Davis <> wrote:

Hi all,
>In one of my projects I used run_erl to launch Erlang VM in daemon mode, rotate logs, etc.
>But I discovered unexpected performance problem running production application with run_erl. Application caused high iowait.
>After some investigation I found that run_erl does fsync on every log entry, causing disk IO load. Do we need fsync on every log entry.
>Appreciate your valuable comments.
>erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120726/00294fba/attachment.html>

More information about the erlang-questions mailing list