Pregunta

I'm working on a filesystem project based on FUSE. And I want to add some sort of read ahead to it. So I create a thread to process such tasks, but It seems that I made it really slower than I thought.(Even if I just add a idle thread, it makes my program become much more slower than without that, but that do not happened when I added this function to my server program, which do not use fuse)

I did not simply use fuse_main function, instead I read the sshfs's code and try to initialize it by myself with the following functions,

fuse_parse_cmdline
fuse_mount
fcntl
fuse_new
fuse_daemonize
fuse_set_signal_handlers
fuse_loop_mt

and without add the thread, it runs pretty well, but after I add this thread in

pthread_create(&tid, NULL, test, NULL); // function test is just a while(1){}

it get slower(Read a 100M file, without this thread it is 40s, and with that it is nearly 100s)

Is this something to do about schedparam or something else? Hope you guys could give me some advice, like what things I need to check.

Thanks again.

¿Fue útil?

Solución

Your thread is busy waiting, which means it will use as much CPU power as it can. You might want to add a little delay in your thread to let other threads and processes run too:

while (1)
{
    usleep(1000);  /* Sleep for one millisecond */
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top