Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File i/o performance problems #5

Open
mihalicyn opened this issue Jul 26, 2017 · 0 comments
Open

File i/o performance problems #5

mihalicyn opened this issue Jul 26, 2017 · 0 comments

Comments

@mihalicyn
Copy link
Owner

mihalicyn commented Jul 26, 2017

Let's see following code:

-- file have size 34406 bytes
f = io.open("/root/dev/libs_port.patch", 'r')

function fsop()
    f:seek('set', 0)
    s = f:read('all')
end

starttime = os.clock()
for i=1,18000
do
    fsop()
end
endtime = (os.clock() - starttime)

print(s:len())
f:close()

print("os.clock() diff " .. endtime)

Results

9000 fsop ~650 timediff kern
        ~0.18 timediff user
4500 fsop ~320 kernel
        ~0.1 user
18000 fsop ~1280 kernel
            ~0.37 user

As we can see scalability factor is two and times ratio is approximately two.

After that I made some experiments...
/usr/src/external/mit/lua/dist/src/liolib.c
original code

static void read_all (lua_State *L, FILE *f) {
  size_t nr;
  luaL_Buffer b;
  luaL_buffinit(L, &b);
  do {  /* read file in chunks of LUAL_BUFFERSIZE bytes */
    char *p = luaL_prepbuffer(&b);
    nr = fread(p, sizeof(char), LUAL_BUFFERSIZE, f);
    luaL_addsize(&b, nr);
  } while (nr == LUAL_BUFFERSIZE);
  luaL_pushresult(&b);  /* close buffer */
}

change to:

static void read_all (lua_State *L, FILE *f) {
  size_t nr;
  luaL_Buffer b;
  luaL_buffinit(L, &b);
  int fsize = 34406;
  do {  /* read file in chunks of LUAL_BUFFERSIZE bytes */
    char *p = luaL_prepbuffer(&b);
    //nr = fread(p, sizeof(char), LUAL_BUFFERSIZE, f);
    fsize -= LUAL_BUFFERSIZE;
    nr = LUAL_BUFFERSIZE;
    if (fsize < 0)
        nr = fsize + LUAL_BUFFERSIZE;        

    luaL_addsize(&b, nr);
  } while (nr == LUAL_BUFFERSIZE);
  luaL_pushresult(&b);  /* close buffer */
}

and times changes to ~1000 for 18k, ~500 for 9k...
Therefore, performance problems caused by memory allocator not by dofilereadv used in fread implementation.

I'm using code from that repo with NetBSD 7.1 generic kernel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant