Skip to contentSkip to conversation

Performance question

DISCUSSION Philipp Gühring 3 participants 5 messages May 5, 2002 – May 6, 2002

lore
Share & tools
lore
#0 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

Let's say I have a directory with 100.000 files in it. The filenames look like

name1_name2_name3_id

So I have

001_41052_50125_1
001_63216_1212_1
...

I have to create a search engine, that serves for example the 4th Block of 10 files that match the query "001_*_1212_1". The how query would result to 100 files, that are spread across the directory.

Now my question:

Is it faster with ReiserFS to do a bsd_glob("001_*_1212_1") first, which should result to about 100 entries, and then take the entries 40 to 49 from the resulting array?
(Is ReiserFS able to directly return 100 files out of 100000 with the globbing function, or is it an iteration over all files in the directory?)

Or should I do 2 opendir-readdir loops, one to read over the first 39 results, that I do not need, and the second one to geht the results 40 to 49? The problem here is that I have to readdir about 50000 files (40000 to get through the unneeded results, and 10000 to get the 10 results i need) But on the other hand, I do not have to remember 100 files, from which I only need 10.

If ReiserFS has to iterate over 100000 files (the whole directory) to do a "001_*_1212_1" glob, because the binary tree only speeds up known files, but not patterns, then opendir-readdir should be faster, I guess.

Another option would be to use subdirectories like name1/name2/name3/id

So the glob would be "001/*/1212/1", which should be faster, anyway. But on the other hand, I would have to do a lot more directory management, creating and deleting directories ...
And implementing an opendir-readdir search through "001/*/1212/1" will be more work too.

Thanks for all feedback in advance and many greetings,
- --
~ Philipp Gühring [email protected]
~ http://www.livingxml.net/ ICQ UIN: 6588261
~ <xsl:value-of select="file:/home/philipp/.sig"/> -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE81T+elqQ+F+0wB3oRAhw/AKCRH5CbdIMt2+ITpDkNBwcPKYpPqQCgmC2e RrYDyo/GgzqJvnn1jy1HjiY=
=/ABd
-----END PGP SIGNATURE-----

#1 lore raw

Hello!

Quoted 7 lines · Philipp G?hring

Let's say I have a directory with 100.000 files in it.
The filenames look like
name1_name2_name3_id
So I have
001_41052_50125_1
001_63216_1212_1
I have to create a search engine, that serves for example the 4th Block of 10

Quoted 8 lines

files that match the query "001_*_1212_1". The how query would result to 100 files, that are spread across the directory.
Now my question:
Is it faster with ReiserFS to do a bsd_glob("001_*_1212_1") first, which should result to about 100 entries, and then take the entries 40 to 49 from the resulting array?
(Is ReiserFS able to directly return 100 files out of 100000 with the globbing function, or is it an iteration over all files in the directory?)

*glob functions are implemented by various library functions, that do full readdir scans at least once, I believe.

Quoted 2 lines

Or should I do 2 opendir-readdir loops, one to read over the first 39 results, that I do not need, and the second one to geht the results 40 to 49?

In fact I do not see why do you need to do 2 opendir-readdir loops. One loop should be enough.
You just compare each filename returned against your query and and if it matched remember it in separate list. So at the end of readdir loop you have a list of all names in a directory that match your query. And you can apply any additional check in place just not to remember unnecesary files.

Quoted 4 lines

The problem here is that I have to readdir about 50000 files (40000 to get through the unneeded results, and 10000 to get the 10 results i need) But on the other hand, I do not have to remember 100 files, from which I only need 10.

I am completely missing the idea on where these numbers are from. Can you explain in more details.

Quoted 3 lines

If ReiserFS has to iterate over 100000 files (the whole directory) to do a "001_*_1212_1" glob, because the binary tree only speeds up known files, but not patterns, then opendir-readdir should be faster, I guess.

Binary tree is only helps when you know filename, I believe. You calculate a hash and out of that hash you can quickly find desired location. You you come up with a hash that places all filenames like your one near one, this will help, then.

Quoted 7 lines

Another option would be to use subdirectories like name1/name2/name3/id
So the glob would be "001/*/1212/1", which should be faster, anyway. But on the other hand, I would have to do a lot more directory management, creating and deleting directories ...
And implementing an opendir-readdir search through "001/*/1212/1" will be more work too.

Readdir would require less iterations through 001/*, because number of entries will be only 100 as you described above.
You get all these 100 entries and then loop 100 times trying to open 001/${next_name}/1212/1 and deciding whenever you need this file or not. (If it exists of course, or you might get -ENOENT and proceed to next directory).
Also deleting directories would be an overkill.
I think this might be faster in many circumfstances.
Also what you've descrived looks very like to what squid does. And squid people went to reiserfs-raw interface and are quite happy with it.

Bye,
Oleg

#2 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello!

Thank you Oleg for your answers.

Quoted 2 lines

*glob functions are implemented by various library functions, that do full readdir scans at least once, I believe.

I thought I heard about a syscall, that makes it possible to pass the glob to the filesystem, so that the filesystem can optimize globbings as it likes, and pass the result back to the application, but ok.

Quoted 6 lines
Quoted 3 lines

Or should I do 2 opendir-readdir loops, one to read over the first 39 results, that I do not need, and the second one to geht the results 40 to 49?

In fact I do not see why do you need to do 2 opendir-readdir loops. One loop should be enough.

Yeah. Sure. My mistake. One opendir, and 2 readdir loops. The first one skips over unneeded results and the second one serves the data.

Quoted 5 lines

You just compare each filename returned against your query and and if it matched remember it in separate list. So at the end of readdir loop you have a list of all names in a directory that match your query. And you can apply any additional check in place just not to remember unnecesary files.

Quoted 7 lines
Quoted 4 lines

The problem here is that I have to readdir about 50000 files (40000 to get through the unneeded results, and 10000 to get the 10 results i need) But on the other hand, I do not have to remember 100 files, from which I only need 10.

I am completely missing the idea on where these numbers are from. Can you explain in more details.

I will try so.
I have a table with 100000 files. A complete search would result for example 100 files, which are spread across the whole directory.
About every thousand files, there is one file, that matches the query. Since the client does not want to get 100 files at once, at first I return only 10 results for the first page, and the user can navigate page-wise.

So I built up the scenario where the user now wants the see results 40-49 from the query "001_*_1212_1",
which I assume as normal behaviour for my application.

Quoted 1 line

Binary tree is only helps when you know filename, I believe.

Ok.

Quoted 7 lines

Readdir would require less iterations through 001/*, because number of entries will be only 100 as you described above.
You get all these 100 entries and then loop 100 times trying to open 001/${next_name}/1212/1 and deciding whenever you need this file or not. (If it exists of course, or you might get -ENOENT and proceed to next directory).
Also deleting directories would be an overkill.

So the question is, how big that overkill is. Is there perhaps a benchmark that tested it already?

Quoted 3 lines

I think this might be faster in many circumfstances.
Also what you've descrived looks very like to what squid does. And squid people went to reiserfs-raw interface and are quite happy with it.

I think the difference to squid is that they only need one result, not a part of a search, with more than one result.
But I am thinking about using reiserfs-raw too ...
(At the moment flexibility has still more priority for me than raw performance)

Many greetings,
- --
~ Philipp G?hring [email protected]
~ http://www.livingxml.net/ ICQ UIN: 6588261
~ <xsl:value-of select="file:/home/philipp/.sig"/> -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE81WFGlqQ+F+0wB3oRAtYSAJsGgaHnsohasbrjnJEQWAhi4tatSwCfQXDB dGlKoxKq0vcB0jHMOV6AEWQ=
=heIa
-----END PGP SIGNATURE-----

#3 lore raw

Hello!

Quoted 5 lines · Philipp G?hring
Quoted 2 lines

*glob functions are implemented by various library functions, that do full readdir scans at least once, I believe.

I thought I heard about a syscall, that makes it possible to pass the glob to the filesystem, so that the filesystem can optimize globbings as it likes, and pass the result back to the application, but ok.

I do not think something like that exists in Linux. But if you come up with man page from section 2...

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Or should I do 2 opendir-readdir loops, one to read over the first 39 results, that I do not need, and the second one to geht the results 40 to 49?

In fact I do not see why do you need to do 2 opendir-readdir loops. One loop should be enough.

Yeah. Sure. My mistake. One opendir, and 2 readdir loops. The first one skips over unneeded results and the second one serves the data.

No. Still I think you need only one loop anyway, like this:
<pseudocode>
DIR=opendir(name);

while((result=readdir(DIR)) != NULL) {
	if ( check_filename_criteria(result->filename) ) {
		add_to_list_of_files_to_process(result->filename);
	}
}
for i in list_of_files_to_process {
	process_file(i);
}

So only one loop, and the second one does not count because it is serves actual data.

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

The problem here is that I have to readdir about 50000 files (40000 to get through the unneeded results, and 10000 to get the 10 results i need) But on the other hand, I do not have to remember 100 files, from which I only need 10.

I am completely missing the idea on where these numbers are from. Can you explain in more details.

Quoted 9 lines

I will try so.
I have a table with 100000 files. A complete search would result for example 100 files, which are spread across the whole directory.
About every thousand files, there is one file, that matches the query. Since the client does not want to get 100 files at once, at first I return only 10 results for the first page, and the user can navigate page-wise. So I built up the scenario where the user now wants the see results 40-49 from the query "001_*_1212_1",
which I assume as normal behaviour for my application.

Ah, I see what you mean. If you have a lot of resources, you can setup a session and store all the search results for that session at server side. So when second request comes in, you just read search result from the session. Also you kill the session for 5 minutes after 5 minutes of inactivity on it or so. Hm... This requires for cookies to be enabled, though. ;)

Quoted 8 lines
Quoted 7 lines

Readdir would require less iterations through 001/*, because number of entries will be only 100 as you described above.
You get all these 100 entries and then loop 100 times trying to open 001/${next_name}/1212/1 and deciding whenever you need this file or not. (If it exists of course, or you might get -ENOENT and proceed to next directory).
Also deleting directories would be an overkill.

So the question is, how big that overkill is.

I mean that you do not need to delete directories, when they are empty. You only need to create the directory structure once.

Quoted 1 line

Is there perhaps a benchmark that tested it already?

No, I do not think so, but feel free to compose and run your own benchmark.

Quoted 5 lines
Quoted 3 lines

I think this might be faster in many circumfstances.
Also what you've descrived looks very like to what squid does. And squid people went to reiserfs-raw interface and are quite happy with it.

I think the difference to squid is that they only need one result, not a part of a search, with more than one result.

Hm. This is true.

Bye,
Oleg

#4 lore raw
In reply to Oleg Drokin

glob is implemented by the shell not the filesystem. This is not for good reason, it just is. We could write something for you to do it in the filesystem and it would be faster. Is your need for speed critical enough to justify writing something special for it?

Hans

Quoted 83 lines · Oleg Drokin

Hello!

Quoted 11 lines · Philipp G?hring

Let's say I have a directory with 100.000 files in it.
The filenames look like
name1_name2_name3_id
So I have
001_41052_50125_1
001_63216_1212_1
I have to create a search engine, that serves for example the 4th Block of 10 files that match the query "001_*_1212_1". The how query would result to 100 files, that are spread across the directory.
Now my question:
Is it faster with ReiserFS to do a bsd_glob("001_*_1212_1") first, which should result to about 100 entries, and then take the entries 40 to 49 from the resulting array? (Is ReiserFS able to directly return 100 files out of 100000 with the globbing function, or is it an iteration over all files in the directory?)

*glob functions are implemented by various library functions, that do full readdir scans at least once, I believe.

Quoted 3 lines

Or should I do 2 opendir-readdir loops, one to read over the first 39 results, that I do not need, and the second one to geht the results 40 to 49?

In fact I do not see why do you need to do 2 opendir-readdir loops. One loop should be enough.
You just compare each filename returned against your query and and if it matched remember it in separate list. So at the end of readdir loop you have a list of all names in a directory that match your query. And you can apply any additional check in place just not to remember unnecesary files.

Quoted 4 lines

The problem here is that I have to readdir about 50000 files (40000 to get through the unneeded results, and 10000 to get the 10 results i need) But on the other hand, I do not have to remember 100 files, from which I only need 10.

I am completely missing the idea on where these numbers are from. Can you explain in more details.

Quoted 3 lines

If ReiserFS has to iterate over 100000 files (the whole directory) to do a "001_*_1212_1" glob, because the binary tree only speeds up known files, but not patterns, then opendir-readdir should be faster, I guess.

Binary tree is only helps when you know filename, I believe. You calculate a hash and out of that hash you can quickly find desired location. You you come up with a hash that places all filenames like your one near one, this will help, then.

Quoted 7 lines

Another option would be to use subdirectories like
name1/name2/name3/id
So the glob would be "001/*/1212/1", which should be faster, anyway.
But on the other hand, I would have to do a lot more directory management, creating and deleting directories ... And implementing an opendir-readdir search through "001/*/1212/1" will be more work too.

Readdir would require less iterations through 001/*, because number of entries will be only 100 as you described above.
You get all these 100 entries and then loop 100 times trying to open 001/${next_name}/1212/1 and deciding whenever you need this file or not. (If it exists of course, or you might get -ENOENT and proceed to next directory).
Also deleting directories would be an overkill.
I think this might be faster in many circumfstances.
Also what you've descrived looks very like to what squid does. And squid people went to reiserfs-raw interface and are quite happy with it.

Bye,
Oleg