I suggest add **FILE READ BUFFER** to DC++

Archived discussion about features (predating the use of Bugzilla as a bug and feature tracker)

Moderator: Moderators

Locked
KatanaTam
Posts: 10
Joined: 2004-10-17 08:01
Contact:

I suggest add **FILE READ BUFFER** to DC++

Post by KatanaTam » 2004-10-17 08:30

I had wrote the code, and I really add to my modify DC++ version.
with 1M buffer per uploading file, my hdd was much quiet!!

I think DC++ is a very good P2P software that could be use in a LAN,
Not like INTERNET, a LAN network's speed is too fast, I write a speed
limit on my client, and I Limit the speed at 1M/s, with 5 slots, my HDD
was seek all the time, I think this is too bad for HDD.

Here is the Read Buffer Code, Wish Can be use in later DC++ version.
And anyother can download my modify version to test this function.

// client\File.h

Code: Select all

class BufferedInputStream : public InputStream {
public:

	BufferedInputStream(InputStream* aStream, size_t aBufSize = SETTING(BUFFER_SIZE) * 1024) : is(aStream), pos(0), dataSize(0), bufSize(aBufSize), buf(new u_int8_t[bufSize]) { }
	virtual ~BufferedInputStream() { 
		delete is;
		delete buf;
	}

	size_t read(void* rbuf, size_t& len){
		u_int8_t* b = (u_int8_t*)rbuf;
		size_t l2 = len;

		while (l2 > 0){
			if (dataSize == 0 || pos >= dataSize){
				dataSize = is->read(buf, bufSize);
				if (dataSize == 0) return (len - l2);
				pos = 0;
			}

			size_t n = min(dataSize - pos, l2);
			memcpy(b, buf + pos, n);
			pos += n;
			l2  -= n;
			b   += n;
		}
		return len;
	}

// client\UploadManager.cpp
// Add to the UploadManager::prepareFile(), can locate the code with the extra code.
// Modify based on DC++ 0.4034

Code: Select all

	// Read Buffer InputStream
	/* Added code start */
	{
		size_t bufSize = SETTING(BUFFER_SIZE) * 1024;
		if ((size - aStartPos) > 10240  &&  bufSize > 0){
			if ((size - aStartPos) < bufSize){
				bufSize = size - aStartPos;
			}
			is = new BufferedInputStream(is, bufSize);
		}
	}
	/* Added code end */

	Upload* u = new Upload();
	u->setUserConnection(aSource);
	u->setFile(is);
	u->setSize(size);
	u->setStartPos(aStartPos);
	u->setFileName(file);
	u->setLocalFileName(file);
After all, I am a chinese, forgive my poor english ^_^

GargoyleMT
DC++ Contributor
Posts: 3212
Joined: 2003-01-07 21:46
Location: .pa.us

Post by GargoyleMT » 2004-10-18 10:25

Windows doesn't cache the uploaded files well enough? :-( I'm not sure how I feel about read buffer code in DC++.
compile.txt wrote:To increase the chances of your patch being accepted, mail them to me as diffs against the latest code you can find (in the cvs repository on sourceforge most probably). You can find a lot of information about diff and patch by googling for it. I like unified format (diff -uNr). By submitting a patch, you agree to that I get copyright of it. This to avoid stupid situations later on where the copyright is split out over a million people, each of which could stop further distribution of DC++. If you don't like this, start your own distribution, if you're lucky it might become more popular than the original =). Please state explicitly in the email that you give me copyright over the code if the submission is larger than trivial.

KatanaTam
Posts: 10
Joined: 2004-10-17 08:01
Contact:

Post by KatanaTam » 2004-10-18 10:40

The reading buffer offer by window is toooooooo small.
if you upload speed reach 1M/s, and have 3~5 upload thread, DC++'s send size is 64K,
So, DC++ need read 3~5 file in 1s about many many time.

windows buffer too small, and make HDD seek all the time..

Add my code, and comply a spec version, compare tow version DC++ when reading speed more then 500K( need 3 more upload thread, you will find the diff)

Locked