473,396 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

VB.NET Really slow filestream

Hello all, I'm new here and I've searched a lot before posting my question,
but I can't seem to find a solution to my problem.

I'm working on a database program that I created myself, I created my own
file format and I store information about clients in there. So far, so good,
but when I try to search the content of my file, that's where it becomes
slow....I try to check if a byte is than 0 in every client's
profile....there are 100 000 clients and the file size is about 200mb.

It goes something like this....

Dim objFile As New System.IO.FileStream("Clients.pcf", IO.FileMode.Open)

For i = 0 To 99999
If Results(i) Then
objFile.Position = (Jump * i) + position
If objFile.ReadByte() 0 Then
Results(i) = False
End If
End If
Next

Results() is an array of Bool and is used to indicate if the client matches
what I'm looking for. It is used several times by different Subs and passed
as an argument.
Jump indicates the length of each client's profile in bytes.
Position indicates where the information is located within the client's
profile.

My computer is old (1gHz), but still, a task like that takes almost 30
seconds...I found out that this line slows everything down: objFile.Position
= (Jump * i) + position, but a multiplication is not supposed to take that
long (I've tried it separately) and if I click a second time on the button
that handles that event, it takes less that a second to get my results....

I've even looked at the CPU usage and it goes up only for the
second....what's happening? Is VB copying my file somewhere?

I must say that I'm more that confused right now....I'm sorry if this is a
long post, but it's a pretty complex situation and I would appreciate every
suggestion.
Dec 12 '07 #1
8 2845

"Frank" <Fr***@discussions.microsoft.comwrote in message
news:06**********************************@microsof t.com...
Hello all, I'm new here and I've searched a lot before posting my
question,
but I can't seem to find a solution to my problem.

I'm working on a database program that I created myself, I created my own
file format and I store information about clients in there. So far, so
good,
but when I try to search the content of my file, that's where it becomes
slow....I try to check if a byte is than 0 in every client's
profile....there are 100 000 clients and the file size is about 200mb.

It goes something like this....

Dim objFile As New System.IO.FileStream("Clients.pcf", IO.FileMode.Open)

For i = 0 To 99999
If Results(i) Then
objFile.Position = (Jump * i) + position
If objFile.ReadByte() 0 Then
Results(i) = False
End If
End If
Next

Results() is an array of Bool and is used to indicate if the client
matches
what I'm looking for. It is used several times by different Subs and
passed
as an argument.
Jump indicates the length of each client's profile in bytes.
Position indicates where the information is located within the client's
profile.

My computer is old (1gHz), but still, a task like that takes almost 30
seconds...I found out that this line slows everything down:
objFile.Position
= (Jump * i) + position, but a multiplication is not supposed to take that
long (I've tried it separately) and if I click a second time on the button
that handles that event, it takes less that a second to get my results....

I've even looked at the CPU usage and it goes up only for the
second....what's happening? Is VB copying my file somewhere?

I must say that I'm more that confused right now....I'm sorry if this is a
long post, but it's a pretty complex situation and I would appreciate
every
suggestion.
It is not the multiply that takes the time. It is the objFile.Position that
is taking the time.

LS

Dec 12 '07 #2
"Frank" <Fr***@discussions.microsoft.comschrieb
Dim objFile As New System.IO.FileStream("Clients.pcf",
IO.FileMode.Open)

For i = 0 To 99999
If Results(i) Then
objFile.Position = (Jump * i) + position
If objFile.ReadByte() 0 Then
Results(i) = False
End If
End If
Next

Results() is an array of Bool and is used to indicate if the client
matches what I'm looking for. It is used several times by different
Subs and passed as an argument.
Jump indicates the length of each client's profile in bytes.
Position indicates where the information is located within the
client's profile.

My computer is old (1gHz), but still, a task like that takes almost
30 seconds...
Usually, a whole cluster (4096 bytes) is read, not only 1 byte. At the
application level, it is only 100,000 bytes, at the file system level ~390
MB (100,000 x 4.096), physically the whole file (some read ops hit the same
cluster). (perhaps technically not completely correct, but you get the
point) Including some overhead, this can take a while. Though, 30 seconds
seems to be a bit long. Don't know why this is. The 2nd time, everything is
already in OS' cache, so it's extremley faster.

(I experienced the same trying to read the chunks of an AVI file. Many times
reading very few bytes couldn't be that slow - I thought.)
Armin

Dec 12 '07 #3
Well, then how do I search faster, what can I do to solve the problem?
Dec 12 '07 #4
"Frank" <Fr***@discussions.microsoft.comschrieb
Well, then how do I search faster, what can I do to solve the
problem?
Use a database.
Armin
Dec 12 '07 #5
like MSDE or mySQL.

Regards,

Trevor Benedict

"Armin Zingler" <az*******@freenet.dewrote in message
news:uN**************@TK2MSFTNGP02.phx.gbl...
"Frank" <Fr***@discussions.microsoft.comschrieb
>Well, then how do I search faster, what can I do to solve the
problem?

Use a database.
Armin

Dec 12 '07 #6
=?Utf-8?B?RnJhbms=?= <Fr***@discussions.microsoft.comwrote in
news:5C**********************************@microsof t.com:
Well, then how do I search faster, what can I do to solve the problem?
Like others have said, use a real database :-)

Or, use XML, and then you can read it in via an XML reader. However,
searching large XML files is still quite slow, due to the lack of keys.

Or as Armin pointed out, you should read data in large blocks - rather than
reading a single byte at the time, reader a large chunk.

Or you can maintain an index of data like a real DBMS does.

But in general, you're reinventing the wheel. Database systems take YEARs
to perfect and is generally something people avoid writing themselves.

--
sp**********@rogers.com (Do not e-mail)
Dec 13 '07 #7
"Trevor Benedict" <Tr********@yahoo.comwrote in news:#q$peBRPIHA.5164
@TK2MSFTNGP03.phx.gbl:
like MSDE or mySQL.
Or SQL 2005 Express Edition
--
sp**********@rogers.com (Do not e-mail)
Dec 13 '07 #8
I think the advise to turn to a real DB is sound, this is the kind of thing
they do best. But if you want to 'roll your own', then maybe there are a few
things you might want to look at. You talk about the file stream being
really slow; compared to what? Have you actually implemented this file
structure in a different language so that you have something to compare to?
Based on your description, the obvious (to me anyway) problem is that you
are IO bound. The fact that a second pass (after the OS has cached the file)
takes only a second, clearly says where the problem lies. 30 seconds to read
200MB seems a bit long, could the file be badly fragmented? You might want
to defragment the drive to see if it improves the search time. If that does
not help, maybe a faster hard drive will!
If none of the above helps (enough), and you still want to do your own file
structure, consider keeping a seperate parallel record structure for each of
the clients that maintains the state of your Boolean flags, or any other
search criteria that is time critical.
The idea here is to have a much smaller file to read, that will still give
you the ability to determine which records match your criteria. Of course,
you now have the problem of keeping the to files in synch.
--
Terry
"Frank" wrote:
Well, then how do I search faster, what can I do to solve the problem?
Dec 13 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Tom | last post by:
I am working with the this object as oppose to the StreamReader object becuase I need to access a file (to find the contents) while an external application is updating the file. When I was...
13
by: Stuart | last post by:
I have converted a VB6 app to VB.NET. It's function is to generate reports from a Random Access file but the .NET version is pathetically slow compared to the VB6 version. I think I need to to...
4
by: Marty | last post by:
Hi, I use a streamwriter object to write in a text files hundreds time per seconds. When my file get very big, can this process is subject to slow down my application? Here is part of my...
7
by: Nathan Sokalski | last post by:
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving,...
5
by: Eric Cadwell | last post by:
Is there a faster way to write the last 100K of a large file? This code takes almost two minutes to run on my machine. int buffer = 100000; int length = 2000000000; string file =...
5
by: rony_16 | last post by:
Hi, I have a problem downloading a file . after i connect to the website and get the stream , i treing to write the file on the HD. public void SaveStreamToFile(string filePath, Stream stream) {...
1
by: fcharby | last post by:
Hello all, I'm new here and I've searched a lot before posting my question, but I can't seem to find a solution to my problem. I'm working on a database program that I created myself, I created my...
5
by: fcharby | last post by:
Hello all, I'm new here and I've searched a lot before posting my question, but I can't seem to find a solution to my problem. I'm working on a database program that I created myself, I created my...
10
by: cellus205 | last post by:
Hows it going everyone. Im still pretty new to vb .net, and am having a little trouble. I am loading a tab delimited txt file into an access database, and parsing the text to extract some of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.