Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit02ac17b

Browse files
committed
Add load balance for backup threads.
1 parent3eb1013 commit02ac17b

File tree

4 files changed

+40
-17
lines changed

4 files changed

+40
-17
lines changed

‎backup.c

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ typedef struct
4747
parray*files;
4848
parray*prev_files;
4949
constXLogRecPtr*lsn;
50-
unsignedintstart_file_idx;
51-
unsignedintend_file_idx;
5250
}backup_files_args;
5351

5452
/*
@@ -106,6 +104,7 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
106104
pthread_tstream_thread;
107105
backup_files_args*backup_threads_args[num_threads];
108106

107+
109108
/* repack the options */
110109
boolsmooth_checkpoint=bkupopt.smooth_checkpoint;
111110
pgBackup*prev_backup=NULL;
@@ -315,27 +314,35 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
315314
if (num_threads<1)
316315
num_threads=1;
317316

317+
/* sort by size for load balancing */
318+
parray_qsort(backup_files_list,pgFileCompareSize);
319+
320+
/* init thread args with own file lists */
318321
for (i=0;i<num_threads;i++)
319322
{
320323
backup_files_args*arg=pg_malloc(sizeof(backup_files_args));
321324
arg->from_root=pgdata;
322325
arg->to_root=path;
323-
arg->files=backup_files_list;
326+
arg->files=parray_new();
324327
arg->prev_files=prev_files;
325328
arg->lsn=lsn;
326-
arg->start_file_idx=i* (parray_num(backup_files_list)/num_threads);
327-
if (i==num_threads-1)
328-
arg->end_file_idx=parray_num(backup_files_list);
329-
else
330-
arg->end_file_idx= (i+1)* (parray_num(backup_files_list)/num_threads);
329+
backup_threads_args[i]=arg;
330+
}
331+
332+
/* balance load between threads */
333+
for (i=0;i<parray_num(backup_files_list);i++)
334+
{
335+
intcur_thread=i %num_threads;
336+
parray_append(backup_threads_args[cur_thread]->files,
337+
parray_get(backup_files_list,i));
338+
}
331339

340+
/* Run threads */
341+
for (i=0;i<num_threads;i++)
342+
{
332343
if (verbose)
333-
elog(WARNING,"Start thread for start_file_idx:%i end_file_idx:%i num:%li",
334-
arg->start_file_idx,
335-
arg->end_file_idx,
336-
parray_num(backup_files_list));
337-
backup_threads_args[i]=arg;
338-
pthread_create(&backup_threads[i],NULL, (void*(*)(void*))backup_files,arg);
344+
elog(WARNING,"Start thread num:%li",parray_num(backup_threads_args[i]->files));
345+
pthread_create(&backup_threads[i],NULL, (void*(*)(void*))backup_files,backup_threads_args[i]);
339346
}
340347

341348
/* Wait theads */
@@ -911,7 +918,7 @@ backup_files(void *arg)
911918
gettimeofday(&tv,NULL);
912919

913920
/* backup a file or create a directory */
914-
for (i=arguments->start_file_idx;i<arguments->end_file_idx;i++)
921+
for (i=0;i<parray_num(arguments->files);i++)
915922
{
916923
intret;
917924
structstatbuf;

‎dir.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,21 @@ pgFileComparePathDesc(const void *f1, const void *f2)
193193
return-pgFileComparePath(f1,f2);
194194
}
195195

196+
/* Compare two pgFile with their size */
197+
int
198+
pgFileCompareSize(constvoid*f1,constvoid*f2)
199+
{
200+
pgFile*f1p=*(pgFile**)f1;
201+
pgFile*f2p=*(pgFile**)f2;
202+
203+
if (f1p->size>f2p->size)
204+
return1;
205+
elseif (f1p->size<f2p->size)
206+
return-1;
207+
else
208+
return0;
209+
}
210+
196211
/* Compare two pgFile with their modify timestamp. */
197212
int
198213
pgFileCompareMtime(constvoid*f1,constvoid*f2)

‎pg_arman.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ main(int argc, char *argv[])
172172
elog(ERROR,"delete command needs ARCLOG_PATH (-A, --arclog-path) to be set");
173173

174174
/* setup exclusion list for file search */
175-
for (i=0;pgdata_exclude[i];i++)/* find first empty slot */
176-
;
175+
for (i=0;pgdata_exclude[i];i++);/* find first empty slot */
176+
177177
if (arclog_path)
178178
pgdata_exclude[i++]=arclog_path;
179179

‎pg_arman.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ extern void pgFileFree(void *file);
284284
externpg_crc32pgFileGetCRC(pgFile*file);
285285
externintpgFileComparePath(constvoid*f1,constvoid*f2);
286286
externintpgFileComparePathDesc(constvoid*f1,constvoid*f2);
287+
externintpgFileCompareSize(constvoid*f1,constvoid*f2);
287288
externintpgFileCompareMtime(constvoid*f1,constvoid*f2);
288289
externintpgFileCompareMtimeDesc(constvoid*f1,constvoid*f2);
289290

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp