I need to be able to write to a file simultaneously from approximately 4
different threads. I'm working on a program that will download parts of a
file and combine the parts. Each thread will have an offset from zero and a
length to write. None of the threads will overlap in the file position.
Is it possible to have the file open (shared) by multiple threads? I'm
guessing that i'd use a filestream with some sort of sharing. Looking for
some pointers and/or examples. Thanks! 10 1685
I need to be able to write to a file simultaneously from approximately
4 different threads. I'm working on a program that will download parts
of a file and combine the parts. Each thread will have an offset from
zero and a length to write. None of the threads will overlap in the
file position.
Is it possible to have the file open (shared) by multiple threads? I'm
guessing that i'd use a filestream with some sort of sharing. Looking
for some pointers and/or examples. Thanks!
Wouldn't it just be simpler to have the multiple threads write to different
files and combine them at the end by creating the final file at this point,
drawing it's data from these other file in sequence?
--
Rory
>
Wouldn't it just be simpler to have the multiple threads write to
different files and combine them at the end by creating the final file at
this point, drawing it's data from these other file in sequence?
No, I'm using a program that does that right now and it creates thousands of
small files and then combines them when it's all done. This causes constant
hard drive activity and my computer is unusable while the program is doing
this. So i'm trying to duplicate the program and combine the data on the
fly, only writing the one file on the hard drive.
I've been leaning toward having one "file manager" thread that I pass a byte
array & file offset and let it do the writing.
I'm just curious why you chose four threads. I mean, if you want something
optimal, I would think the thread count is based on a buffer size. In
theory, I doubt the question matters if there was two or twenty-two threads.
"Terry Olsen" wrote:
I need to be able to write to a file simultaneously from approximately 4
different threads. I'm working on a program that will download parts of a
file and combine the parts. Each thread will have an offset from zero and a
length to write. None of the threads will overlap in the file position.
Is it possible to have the file open (shared) by multiple threads? I'm
guessing that i'd use a filestream with some sort of sharing. Looking for
some pointers and/or examples. Thanks!
Because I'm downloading yEncoded files from a usenet news group. Nothing
shifty here, perfectly legal. Grabbing Fan-Made Mission files from
alt.binaries.ga mes.thief
My news server allows 4 connections. So i'll be simultaneously downloading 4
parts of the file at a time, yDecoding them on the fly, and writing the
decoded bytes to the file.
Some news servers allow upwards of 10 to 20 connections, so it's possible
that someone else using the program may have that many threads running and
all trying to write to the file.
I've built a FileWriter class that lets me pass the Filename, byte array,
file offset, and length. I used SyncLock to make sure each thread waits its
turn. Thanks to the guy who made that suggestion. I haven't tested it yet
but I have high hopes that it will work well.
"ModelBuild er" <Mo**********@d iscussions.micr osoft.comwrote in message
news:5A******** *************** ***********@mic rosoft.com...
I'm just curious why you chose four threads. I mean, if you want
something
optimal, I would think the thread count is based on a buffer size. In
theory, I doubt the question matters if there was two or twenty-two
threads.
"Terry Olsen" wrote:
>I need to be able to write to a file simultaneously from approximately 4 different threads. I'm working on a program that will download parts of a file and combine the parts. Each thread will have an offset from zero and a length to write. None of the threads will overlap in the file position.
Is it possible to have the file open (shared) by multiple threads? I'm guessing that i'd use a filestream with some sort of sharing. Looking for some pointers and/or examples. Thanks!
Terry Olsen wrote:
Because I'm downloading yEncoded files from a usenet news group.
Nothing shifty here, perfectly legal. Grabbing Fan-Made Mission files
from alt.binaries.ga mes.thief
My news server allows 4 connections. So i'll be simultaneously
downloading 4 parts of the file at a time, yDecoding them on the fly,
and writing the decoded bytes to the file.
But surely, using 4 connections won't make it download any faster? Isn't the
download speed limited by the speed of your Internet connection? I suppose
it might even make it slower as the disk drive head on the news server has
to keep moving between four parts of the file.
Andrew
I'm sorry. For some reason I had thought you were talking about four
System.Threadin g.Threads, not discussion threads.
"Terry Olsen" wrote:
Because I'm downloading yEncoded files from a usenet news group. Nothing
shifty here, perfectly legal. Grabbing Fan-Made Mission files from
alt.binaries.ga mes.thief
My news server allows 4 connections. So i'll be simultaneously downloading 4
parts of the file at a time, yDecoding them on the fly, and writing the
decoded bytes to the file.
Some news servers allow upwards of 10 to 20 connections, so it's possible
that someone else using the program may have that many threads running and
all trying to write to the file.
I've built a FileWriter class that lets me pass the Filename, byte array,
file offset, and length. I used SyncLock to make sure each thread waits its
turn. Thanks to the guy who made that suggestion. I haven't tested it yet
but I have high hopes that it will work well.
"ModelBuild er" <Mo**********@d iscussions.micr osoft.comwrote in message
news:5A******** *************** ***********@mic rosoft.com...
I'm just curious why you chose four threads. I mean, if you want
something
optimal, I would think the thread count is based on a buffer size. In
theory, I doubt the question matters if there was two or twenty-two
threads.
"Terry Olsen" wrote:
I need to be able to write to a file simultaneously from approximately 4
different threads. I'm working on a program that will download parts of a
file and combine the parts. Each thread will have an offset from zero and
a
length to write. None of the threads will overlap in the file position.
Is it possible to have the file open (shared) by multiple threads? I'm
guessing that i'd use a filestream with some sort of sharing. Looking for
some pointers and/or examples. Thanks!
I've been leaning toward having one "file manager" thread that I pass
a byte array & file offset and let it do the writing.
Sounds interesting. Hows about adding each ByteArray or stream to a queue
together with a description of it s destination byterange. Then your filemanager
can be the only thread to write to the file and can deal with the bytearrays/streams
as they are completed and added to said queue.
--
Rory
But surely, using 4 connections won't make it download any faster? Isn't
the download speed limited by the speed of your Internet connection? I
suppose it might even make it slower as the disk drive head on the news
server has to keep moving between four parts of the file.
I have an 8MB cable connection. The news server caps each connection to
40kbs. So 4 connections gives me 160kps effective speed.
And the news server shouldn't have any problem with the disk drive heads as
the ISP has hundreds of thousands of subscribers, many, i'm sure, use the
newsgroups.
"ModelBuild er" <Mo**********@d iscussions.micr osoft.comwrote in message
news:89******** *************** ***********@mic rosoft.com...
I'm sorry. For some reason I had thought you were talking about four
System.Threadin g.Threads, not discussion threads.
You were correct. I'll have 4 System.Threadin g.Threads running, each
downloading a part of the file. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ben Dewey |
last post by:
Project:
----------------------------
I am creating a HTTPS File Transfer App using ASP.NET and C#. I am
utilizing ActiveDirectory and windows security to manage the
permissions. Why reinvent the wheel, right? Everything so far is
working well with the Active Directory. The problem I am having is
with adding File Permissions to a directory. I am currently using
some code courtesy of "Willy Denoyette "
|
by: Dante |
last post by:
I have moved a heavy calculation inside my application to multiple threads.
Previously I was saving the results to a file and after finishing I
collected them all in one mdb file. Unfortunately this approach is too slow
so I decided to save all in one mdb file; now each thread is writing into
its own temporary table inside the MDB to avoid thread collisions and
locking.
But, is this approach thread safe? Currently I am only guessing, but...
|
by: arne.muller |
last post by:
Hello,
I've come across some problems reading strucutres from binary files.
Basically I've some strutures
typedef struct {
int i;
double x;
int n;
double *mz;
|
by: bonk |
last post by:
I am trying to create a stream that writes text to a file and:
- automatically creates a new file once the current file exceeds a
certain size
- makes it possible to be used by multiple threads and/or processes so
that multiple threads/processes can write to the same file (all threads
use the same instance of the stream, processes use a different instance
but still may point to the same file)
Could you point me in the correct...
|
by: patrickdepinguin |
last post by:
Hi,
I need to write large quantities of data to a file in C. The data comes from statistics that are continuously gathered from a simulator, and in order to not slow the whole thing down I would obviously want the writes to go as fast and efficient as possible.
Since I/O operations are rather slow, I was thinking that using a large buffer would be better than writing each data point every time. Each data point calls my function, at which...
| |
by: Chuck Cheeze |
last post by:
This might be in the wrong group, but...
Here is an example of my data:
entry_id cat_id
1 20
2 25
3 30
4 25
5 35
|
by: Cramer |
last post by:
I've finally gotton board with TDD (test driven development) and wow is it
effective! I went from sceptic to True Believer with my first effort.
My question: According to the various books and articles I have read about
TDD, a good unit test does not rely on the database or other such
external/environmental conditions. More generally, a good unit test is
atomic and makes as few assumptions about its runtime environment as
possible. But...
|
by: AAaron123 |
last post by:
I have a timer. At each tick, say 0.1 second, I write a file.
If it takes more than 0.1 second to write the file the app will not work
correctly.
How can I tell in the tick event if the previous file finished writing so I
can skip writing at that time?
I write using the Bitmap.Save method.
|
by: Krzysztof Retel |
last post by:
Hi guys,
I am struggling writing fast UDP server. It has to handle around 10000
UDP packets per second. I started building that with non blocking
socket and threads. Unfortunately my approach does not work at all.
I wrote a simple case test: client and server. The client sends 2200
packets within 0.137447118759 secs. The tcpdump received 2189 packets,
which is not bad at all.
But the server only handles 700 -- 870 packets, when it is...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |