Skip to content

Commit

Permalink
version 0.6.6 - some network fixes and download/upload optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Oct 30, 2014
1 parent a8fd1c5 commit 5dc9cdb
Show file tree
Hide file tree
Showing 28 changed files with 413 additions and 154 deletions.
4 changes: 2 additions & 2 deletions Telegram/DeployLinux.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AppVersionStr=0.6.5
AppVersion=6005
AppVersionStr=0.6.6
AppVersion=6006

if [ ! -f "./../Linux/Release/deploy/$AppVersionStr/tlinuxupd$AppVersion" ]; then
echo "tlinuxupd$AppVersion not found!";
Expand Down
4 changes: 2 additions & 2 deletions Telegram/DeployLinux32.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AppVersionStr=0.6.5
AppVersion=6005
AppVersionStr=0.6.6
AppVersion=6006

if [ ! -f "./../Linux/Release/deploy/$AppVersionStr/tlinux32upd$AppVersion" ]; then
echo "tlinux32upd$AppVersion not found!"
Expand Down
4 changes: 2 additions & 2 deletions Telegram/DeployMacWin.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AppVersionStr=0.6.5
AppVersion=6005
AppVersionStr=0.6.6
AppVersion=6006

if [ ! -f "./../Mac/Release/deploy/$AppVersionStr/tmacupd$AppVersion" ]; then
echo "tmacupd$AppVersion not found!"
Expand Down
4 changes: 2 additions & 2 deletions Telegram/DeployWin.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AppVersionStr=0.6.5
AppVersion=6005
AppVersionStr=0.6.6
AppVersion=6006

if [ ! -f "./../Win32/Deploy/deploy/$AppVersionStr/tupdate$AppVersion" ]; then
echo "tupdate$AppVersion not found!"
Expand Down
4 changes: 2 additions & 2 deletions Telegram/PrepareLinux.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AppVersionStr=0.6.5
AppVersion=6005
AppVersionStr=0.6.6
AppVersion=6006

if [ -d "./../Linux/Release/deploy/$AppVersionStr" ]; then
echo "Deploy folder for version $AppVersionStr already exists!"
Expand Down
4 changes: 2 additions & 2 deletions Telegram/PrepareLinux32.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AppVersionStr=0.6.5
AppVersion=6005
AppVersionStr=0.6.6
AppVersion=6006

if [ -d "./../Linux/Release/deploy/$AppVersionStr" ]; then
echo "Deploy folder for version $AppVersionStr already exists!"
Expand Down
4 changes: 2 additions & 2 deletions Telegram/PrepareMac.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AppVersionStr=0.6.5
AppVersion=6005
AppVersionStr=0.6.6
AppVersion=6006

if [ -d "./../Mac/Release/deploy/$AppVersionStr" ]; then
echo "Deploy folder for version $AppVersionStr already exists!"
Expand Down
6 changes: 3 additions & 3 deletions Telegram/PrepareWin.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cd ..\Win32\Deploy
call ..\..\..\TelegramPrivate\Sign.bat tsetup.0.6.5.exe
call ..\..\..\TelegramPrivate\Sign.bat tsetup.0.6.6.exe
call Prepare.exe -path Telegram.exe -path Updater.exe
mkdir deploy\0.6.5\Telegram
move deploy\0.6.5\Telegram.exe deploy\0.6.5\Telegram\
mkdir deploy\0.6.6\Telegram
move deploy\0.6.6\Telegram.exe deploy\0.6.6\Telegram\
cd ..\..\Telegram
6 changes: 3 additions & 3 deletions Telegram/Setup.iss
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

#define MyAppShortName "Telegram"
#define MyAppName "Telegram Desktop"
#define MyAppVersion "0.6.5"
#define MyAppVersionZero "0.6.5"
#define MyAppFullVersion "0.6.5.0"
#define MyAppVersion "0.6.6"
#define MyAppVersionZero "0.6.6"
#define MyAppFullVersion "0.6.6.0"
#define MyAppPublisher "Telegram Messenger LLP"
#define MyAppURL "https://tdesktop.com"
#define MyAppExeName "Telegram.exe"
Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ namespace App {
const MTPDphotoSize &d(size.c_photoSize());
if (d.vlocation.type() == mtpc_fileLocation) {
const MTPDfileLocation &l(d.vlocation.c_fileLocation());
return ImagePtr(d.vw.v, d.vh.v, l.vdc_id.v, l.vvolume_id.v, l.vlocal_id.v, l.vsecret.v);
return ImagePtr(d.vw.v, d.vh.v, l.vdc_id.v, l.vvolume_id.v, l.vlocal_id.v, l.vsecret.v, d.vsize.v);
}
} break;
case mtpc_photoCachedSize: {
Expand Down
39 changes: 39 additions & 0 deletions Telegram/SourceFiles/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ Application::Application(int &argc, char **argv) : PsApplication(argc, argv),
connect(&writeUserConfigTimer, SIGNAL(timeout()), this, SLOT(onWriteUserConfig()));
writeUserConfigTimer.setSingleShot(true);

killDownloadSessionsTimer.setSingleShot(true);
connect(&killDownloadSessionsTimer, SIGNAL(timeout()), this, SLOT(killDownloadSessions()));

if (cManyInstance()) {
startApp();
} else {
Expand Down Expand Up @@ -326,10 +329,46 @@ void Application::writeUserConfigIn(uint64 ms) {
}
}

void Application::killDownloadSessionsStart(int32 dc) {
if (killDownloadSessionTimes.constFind(dc) == killDownloadSessionTimes.cend()) {
killDownloadSessionTimes.insert(dc, getms() + MTPKillFileSessionTimeout);
}
if (!killDownloadSessionsTimer.isActive()) {
killDownloadSessionsTimer.start(MTPKillFileSessionTimeout + 5);
}
}

void Application::killDownloadSessionsStop(int32 dc) {
killDownloadSessionTimes.remove(dc);
if (killDownloadSessionTimes.isEmpty() && killDownloadSessionsTimer.isActive()) {
killDownloadSessionsTimer.stop();
}
}

void Application::onWriteUserConfig() {
App::writeUserConfig();
}

void Application::killDownloadSessions() {
uint64 ms = getms(), left = MTPKillFileSessionTimeout;
for (QMap<int32, uint64>::iterator i = killDownloadSessionTimes.begin(); i != killDownloadSessionTimes.end(); ) {
if (i.value() <= ms) {
for (int j = 1; j < MTPDownloadSessionsCount; ++j) {
MTP::killSession(MTP::dld[j] + i.key());
}
i = killDownloadSessionTimes.erase(i);
} else {
if (i.value() - ms < left) {
left = i.value() - ms;
}
++i;
}
}
if (!killDownloadSessionTimes.isEmpty()) {
killDownloadSessionsTimer.start(left);
}
}

void Application::photoUpdated(MsgId msgId, const MTPInputFile &file) {
if (!App::self()) return;

Expand Down
8 changes: 8 additions & 0 deletions Telegram/SourceFiles/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class Application : public PsApplication, public RPCSender {

void writeUserConfigIn(uint64 ms);

void killDownloadSessionsStart(int32 dc);
void killDownloadSessionsStop(int32 dc);

signals:

void peerPhotoDone(PeerId peer);
Expand Down Expand Up @@ -100,10 +103,15 @@ public slots:
void onEnableDebugMode();
void onWriteUserConfig();

void killDownloadSessions();

private:

QMap<MsgId, PeerId> photoUpdates;

QMap<int32, uint64> killDownloadSessionTimes;
QTimer killDownloadSessionsTimer;

void startApp();

typedef QPair<QLocalSocket*, QByteArray> ClientSocket;
Expand Down
16 changes: 10 additions & 6 deletions Telegram/SourceFiles/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Copyright (c) 2014 John Preston, https://tdesktop.com
*/
#pragma once

static const int32 AppVersion = 6005;
static const wchar_t *AppVersionStr = L"0.6.5";
static const int32 AppVersion = 6006;
static const wchar_t *AppVersionStr = L"0.6.6";

static const wchar_t *AppNameOld = L"Telegram Win (Unofficial)";
static const wchar_t *AppName = L"Telegram Desktop";
Expand All @@ -32,7 +32,7 @@ enum {
MTPShortBufferSize = 65535, // of ints, 256 kb
MTPPacketSizeMax = 67108864, // 64 mb
MTPIdsBufferSize = 400, // received msgIds and wereAcked msgIds count stored
MTPCheckResendTimeout = 5000, // how much time passed from send till we resend request or check it's state, in ms
MTPCheckResendTimeout = 10000, // how much time passed from send till we resend request or check it's state, in ms
MTPCheckResendWaiting = 1000, // how much time to wait for some more requests, when resending request or checking it's state, in ms
MTPResendThreshold = 1, // how much ints should message contain for us not to resend, but to check it's state
MTPContainerLives = 600, // container lives 10 minutes in haveSent map
Expand All @@ -41,6 +41,10 @@ enum {
MTPTcpConnectionWaitTimeout = 3000, // 3 seconds waiting for tcp, until we accept http
MTPMillerRabinIterCount = 30, // 30 Miller-Rabin iterations for dh_prime primality check

MTPUploadSessionsCount = 4, // max 4 upload sessions is created
MTPDownloadSessionsCount = 4, // max 4 download sessions is created
MTPKillFileSessionTimeout = 5000, // how much time without upload / download causes additional session kill

MTPEnumDCTimeout = 4000, // 4 seconds timeout for help_getConfig to work (them move to other dc)

MTPDebugBufferSize = 1024 * 1024, // 1 mb start size
Expand Down Expand Up @@ -209,12 +213,12 @@ enum {

LinkCropLimit = 360, // 360px link length max

DownloadPartSize = 32 * 1024, // 32kb for photo
DownloadPartSize = 64 * 1024, // 64kb for photo
DocumentDownloadPartSize = 128 * 1024, // 128kb for document
MaxUploadPhotoSize = 10 * 1024 * 1024, // 10mb photos max
MaxUploadDocumentSize = 1500 * 1024 * 1024, // 1500mb documents max
UseBigFilesFrom = 10 * 1024 * 1024, // mtp big files methods used for files greater than 10mb
MaxFileQueries = 32, // max 32 file parts downloaded at the same time
MaxFileQueries = 16, // max 16 file parts downloaded at the same time

UploadPartSize = 32 * 1024, // 32kb for photo
DocumentMaxPartsCount = 3000, // no more than 3000 parts
Expand All @@ -223,7 +227,7 @@ enum {
DocumentUploadPartSize2 = 128 * 1024, // 128kb for small document ( <= 375mb )
DocumentUploadPartSize3 = 256 * 1024, // 256kb for medium document ( <= 750mb )
DocumentUploadPartSize4 = 512 * 1024, // 512kb for large document ( <= 1500mb )
MaxUploadFileParallelSize = 512 * 1024, // max 512kb uploaded at the same time
MaxUploadFileParallelSize = MTPUploadSessionsCount * 512 * 1024, // max 512kb uploaded at the same time in each session
UploadRequestInterval = 500, // one part each half second, if not uploaded faster

MaxPhotosInMemory = 50, // try to clear some memory after 50 photos are created
Expand Down
59 changes: 54 additions & 5 deletions Telegram/SourceFiles/fileuploader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ Copyright (c) 2014 John Preston, https://tdesktop.com
#include "fileuploader.h"

FileUploader::FileUploader() : sentSize(0), uploading(0) {
memset(sentSizes, 0, sizeof(sentSizes));
nextTimer.setSingleShot(true);
connect(&nextTimer, SIGNAL(timeout()), this, SLOT(sendNext()));
killSessionsTimer.setSingleShot(true);
connect(&killSessionsTimer, SIGNAL(timeout()), this, SLOT(killSessions()));
}

void FileUploader::uploadMedia(MsgId msgId, const ReadyLocalMedia &media) {
Expand Down Expand Up @@ -60,23 +63,49 @@ void FileUploader::currentFailed() {

requestsSent.clear();
docRequestsSent.clear();
queue.remove(uploading);
dcMap.clear();
uploading = 0;
sentSize = 0;
for (int i = 0; i < MTPUploadSessionsCount; ++i) {
sentSizes[i] = 0;
}

sendNext();
}

void FileUploader::killSessions() {
for (int i = 0; i < MTPUploadSessionsCount; ++i) {
MTP::killSession(MTP::upl[i]);
}
}

void FileUploader::sendNext() {
if (sentSize >= MaxUploadFileParallelSize || queue.isEmpty()) return;
if (sentSize >= MaxUploadFileParallelSize) return;

bool killing = killSessionsTimer.isActive();
if (queue.isEmpty()) {
if (!killing) {
killSessionsTimer.start(MTPKillFileSessionTimeout);
}
return;
}

if (killing) {
killSessionsTimer.stop();
}
Queue::iterator i = uploading ? queue.find(uploading) : queue.begin();
if (!uploading) {
uploading = i.key();
} else if (i == queue.end()) {
i = queue.begin();
uploading = i.key();
}
int todc = 0;
for (int dc = 1; dc < MTPUploadSessionsCount; ++dc) {
if (sentSizes[dc] < sentSizes[todc]) {
todc = dc;
}
}
if (i->media.parts.isEmpty()) {
if (i->docSentParts >= i->docPartsCount) {
if (requestsSent.isEmpty() && docRequestsSent.isEmpty()) {
Expand Down Expand Up @@ -125,20 +154,24 @@ void FileUploader::sendNext() {
}
mtpRequestId requestId;
if (i->docSize > UseBigFilesFrom) {
requestId = MTP::send(MTPupload_SaveBigFilePart(MTP_long(i->media.id), MTP_int(i->docSentParts), MTP_int(i->docPartsCount), MTP_string(toSend)), rpcDone(&FileUploader::partLoaded), rpcFail(&FileUploader::partFailed), MTP::upl);
requestId = MTP::send(MTPupload_SaveBigFilePart(MTP_long(i->media.id), MTP_int(i->docSentParts), MTP_int(i->docPartsCount), MTP_string(toSend)), rpcDone(&FileUploader::partLoaded), rpcFail(&FileUploader::partFailed), MTP::upl[todc]);
} else {
requestId = MTP::send(MTPupload_SaveFilePart(MTP_long(i->media.id), MTP_int(i->docSentParts), MTP_string(toSend)), rpcDone(&FileUploader::partLoaded), rpcFail(&FileUploader::partFailed), MTP::upl);
requestId = MTP::send(MTPupload_SaveFilePart(MTP_long(i->media.id), MTP_int(i->docSentParts), MTP_string(toSend)), rpcDone(&FileUploader::partLoaded), rpcFail(&FileUploader::partFailed), MTP::upl[todc]);
}
docRequestsSent.insert(requestId, i->docSentParts);
dcMap.insert(requestId, todc);
sentSize += i->docPartSize;
sentSizes[todc] += i->docPartSize;

i->docSentParts++;
} else {
LocalFileParts::iterator part = i->media.parts.begin();

mtpRequestId requestId = MTP::send(MTPupload_SaveFilePart(MTP_long(i->media.jpeg_id), MTP_int(part.key()), MTP_string(part.value())), rpcDone(&FileUploader::partLoaded), rpcFail(&FileUploader::partFailed), MTP::upl);
mtpRequestId requestId = MTP::send(MTPupload_SaveFilePart(MTP_long(i->media.jpeg_id), MTP_int(part.key()), MTP_string(part.value())), rpcDone(&FileUploader::partLoaded), rpcFail(&FileUploader::partFailed), MTP::upl[todc]);
requestsSent.insert(requestId, part.value());
dcMap.insert(requestId, todc);
sentSize += part.value().size();
sentSizes[todc] += part.value().size();

i->media.parts.erase(part);
}
Expand Down Expand Up @@ -168,7 +201,13 @@ void FileUploader::clear() {
MTP::cancel(i.key());
}
docRequestsSent.clear();
dcMap.clear();
sentSize = 0;
for (int32 i = 0; i < MTPUploadSessionsCount; ++i) {
MTP::killSession(MTP::upl[i]);
sentSizes[i] = 0;
}
killSessionsTimer.stop();
}

void FileUploader::partLoaded(const MTPBool &result, mtpRequestId requestId) {
Expand All @@ -182,12 +221,22 @@ void FileUploader::partLoaded(const MTPBool &result, mtpRequestId requestId) {
currentFailed();
return;
} else {
QMap<mtpRequestId, int32>::iterator dcIt = dcMap.find(requestId);
if (dcIt == dcMap.cend()) { // must not happen
currentFailed();
return;
}
int32 dc = dcIt.value();
dcMap.erase(dcIt);

Queue::const_iterator k = queue.constFind(uploading);
if (i != requestsSent.cend()) {
sentSize -= i.value().size();
sentSizes[dc] -= i.value().size();
requestsSent.erase(i);
} else {
sentSize -= k->docPartSize;
sentSizes[dc] -= k->docPartSize;
docRequestsSent.erase(j);
}
if (k->media.type == ToPreparePhoto) {
Expand Down
5 changes: 4 additions & 1 deletion Telegram/SourceFiles/fileuploader.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class FileUploader : public QObject, public RPCSender {
public slots:

void sendNext();
void killSessions();

signals:

Expand Down Expand Up @@ -98,11 +99,13 @@ public slots:

QMap<mtpRequestId, QByteArray> requestsSent;
QMap<mtpRequestId, int32> docRequestsSent;
QMap<mtpRequestId, int32> dcMap;
uint32 sentSize;
uint32 sentSizes[MTPUploadSessionsCount];

MsgId uploading;
Queue queue;
Queue uploaded;
QTimer nextTimer;
QTimer nextTimer, killSessionsTimer;

};
Loading

0 comments on commit 5dc9cdb

Please sign in to comment.