##// END OF EJS Templates
discovery: slowly increase sampling size...
discovery: slowly increase sampling size Some pathological discovery runs can requires many roundtrip. When this happens things can get very slow. To make the algorithm more resilience again such pathological case. We slowly increase the sample size with each roundtrip (+5%). This will have a negligible impact on "normal" discovery with few roundtrips, but a large positive impact of case with many roundtrips. Asking more question per roundtrip helps to reduce the undecided set faster. Instead of reducing the undecided set a linear speed (in the worst case), we reduce it as a guaranteed (small) exponential rate. The data below show this slow ramp up in sample size: round trip | 1 | 5 | 10 | 20 | 50 | 100 | 130 | sample size | 200 | 254 | 321 | 517 | 2 199 | 25 123 | 108 549 | covered nodes | 200 | 1 357 | 2 821 | 7 031 | 42 658 | 524 530 | 2 276 755 | To be a bit more concrete, lets take a very pathological case as an example. We are doing discovery from a copy of Mozilla-try to a more recent version of mozilla-unified. Mozilla-unified heads are unknown to the mozilla-try repo and there are over 1 million "missing" changesets. (the discovery is "local" to avoid network interference) Without this change, the discovery: - last 1858 seconds (31 minutes), - does 1700 round trip, - asking about 340 000 nodes. With this change, the discovery: - last 218 seconds (3 minutes, 38 seconds a -88% improvement), - does 94 round trip (-94%), - asking about 344 211 nodes (+1%). Of course, this is an extreme case (and 3 minutes is still slow). However this give a good example of how this sample size increase act as a safety net catching any bad situations. We could image a steeper increase than 5%. For example 10% would give the following number: round trip | 1 | 5 | 10 | 20 | 50 | 75 | 100 | sample size | 200 | 321 | 514 | 1 326 | 23 060 | 249 812 | 2 706 594 | covered nodes | 200 | 1 541 | 3 690 | 12 671 | 251 871 | 2 746 254 | 29 770 966 | In parallel, it is useful to understand these pathological cases and improve them. However the current change provides a general purpose safety net to smooth the impact of pathological cases. To avoid issue with older http server, the increase in sample size only occurs if the protocol has not limit on command argument size.

File last commit:

r41367:763b45bc default
r42546:dbd0fcca default
Show More
base85.c
203 lines | 3.8 KiB | text/x-c | CLexer
Yuya Nishihara
base85: switch to policy importer
r32368 /*
base85 codec
Copyright 2006 Brendan Cully <brendan@kublai.com>
This software may be used and distributed according to the terms of
the GNU General Public License, incorporated herein by reference.
Largely based on git's implementation
*/
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include "util.h"
Augie Fackler
base85: allow clang-format oversight...
r36244 static const char b85chars[] =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~";
Yuya Nishihara
base85: switch to policy importer
r32368 static char b85dec[256];
static void b85prep(void)
{
unsigned i;
memset(b85dec, 0, sizeof(b85dec));
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 for (i = 0; i < sizeof(b85chars); i++) {
Yuya Nishihara
base85: switch to policy importer
r32368 b85dec[(int)(b85chars[i])] = i + 1;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 }
Yuya Nishihara
base85: switch to policy importer
r32368 }
static PyObject *b85encode(PyObject *self, PyObject *args)
{
const unsigned char *text;
PyObject *out;
char *dst;
Py_ssize_t len, olen, i;
unsigned int acc, val, ch;
int pad = 0;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 if (!PyArg_ParseTuple(args, PY23("s#|i", "y#|i"), &text, &len, &pad)) {
Yuya Nishihara
base85: switch to policy importer
r32368 return NULL;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 }
Yuya Nishihara
base85: switch to policy importer
r32368
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 if (pad) {
Yuya Nishihara
base85: switch to policy importer
r32368 olen = ((len + 3) / 4 * 5) - 3;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 } else {
Yuya Nishihara
base85: switch to policy importer
r32368 olen = len % 4;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 if (olen) {
Yuya Nishihara
base85: switch to policy importer
r32368 olen++;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 }
Yuya Nishihara
base85: switch to policy importer
r32368 olen += len / 4 * 5;
}
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 if (!(out = PyBytes_FromStringAndSize(NULL, olen + 3))) {
Yuya Nishihara
base85: switch to policy importer
r32368 return NULL;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 }
Yuya Nishihara
base85: switch to policy importer
r32368
dst = PyBytes_AsString(out);
while (len) {
acc = 0;
for (i = 24; i >= 0; i -= 8) {
ch = *text++;
acc |= ch << i;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 if (--len == 0) {
Yuya Nishihara
base85: switch to policy importer
r32368 break;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 }
Yuya Nishihara
base85: switch to policy importer
r32368 }
for (i = 4; i >= 0; i--) {
val = acc % 85;
acc /= 85;
dst[i] = b85chars[val];
}
dst += 5;
}
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 if (!pad) {
Yuya Nishihara
base85: switch to policy importer
r32368 _PyBytes_Resize(&out, olen);
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 }
Yuya Nishihara
base85: switch to policy importer
r32368
return out;
}
static PyObject *b85decode(PyObject *self, PyObject *args)
{
Yuya Nishihara
base85: fix leak on error return from b85decode()...
r39483 PyObject *out = NULL;
Yuya Nishihara
base85: switch to policy importer
r32368 const char *text;
char *dst;
Py_ssize_t len, i, j, olen, cap;
int c;
unsigned int acc;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 if (!PyArg_ParseTuple(args, PY23("s#", "y#"), &text, &len)) {
Yuya Nishihara
base85: switch to policy importer
r32368 return NULL;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 }
Yuya Nishihara
base85: switch to policy importer
r32368
olen = len / 5 * 4;
i = len % 5;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 if (i) {
Yuya Nishihara
base85: switch to policy importer
r32368 olen += i - 1;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 }
if (!(out = PyBytes_FromStringAndSize(NULL, olen))) {
Yuya Nishihara
base85: switch to policy importer
r32368 return NULL;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 }
Yuya Nishihara
base85: switch to policy importer
r32368
dst = PyBytes_AsString(out);
i = 0;
Gregory Szorc
cext: move braces for control statements to same line...
r34438 while (i < len) {
Yuya Nishihara
base85: switch to policy importer
r32368 acc = 0;
cap = len - i - 1;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 if (cap > 4) {
Yuya Nishihara
base85: switch to policy importer
r32368 cap = 4;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 }
Gregory Szorc
cext: move braces for control statements to same line...
r34438 for (j = 0; j < cap; i++, j++) {
Yuya Nishihara
base85: switch to policy importer
r32368 c = b85dec[(int)*text++] - 1;
Yuya Nishihara
base85: fix leak on error return from b85decode()...
r39483 if (c < 0) {
PyErr_Format(
Augie Fackler
base85: allow clang-format oversight...
r36244 PyExc_ValueError,
"bad base85 character at position %d",
(int)i);
Yuya Nishihara
base85: fix leak on error return from b85decode()...
r39483 goto bail;
}
Yuya Nishihara
base85: switch to policy importer
r32368 acc = acc * 85 + c;
}
Gregory Szorc
cext: move braces for control statements to same line...
r34438 if (i++ < len) {
Yuya Nishihara
base85: switch to policy importer
r32368 c = b85dec[(int)*text++] - 1;
Yuya Nishihara
base85: fix leak on error return from b85decode()...
r39483 if (c < 0) {
PyErr_Format(
Augie Fackler
base85: allow clang-format oversight...
r36244 PyExc_ValueError,
"bad base85 character at position %d",
(int)i);
Yuya Nishihara
base85: fix leak on error return from b85decode()...
r39483 goto bail;
}
Yuya Nishihara
base85: switch to policy importer
r32368 /* overflow detection: 0xffffffff == "|NsC0",
* "|NsC" == 0x03030303 */
Yuya Nishihara
base85: fix leak on error return from b85decode()...
r39483 if (acc > 0x03030303 || (acc *= 85) > 0xffffffff - c) {
PyErr_Format(
Augie Fackler
base85: allow clang-format oversight...
r36244 PyExc_ValueError,
"bad base85 sequence at position %d",
(int)i);
Yuya Nishihara
base85: fix leak on error return from b85decode()...
r39483 goto bail;
}
Yuya Nishihara
base85: switch to policy importer
r32368 acc += c;
}
cap = olen < 4 ? olen : 4;
olen -= cap;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 for (j = 0; j < 4 - cap; j++) {
Yuya Nishihara
base85: switch to policy importer
r32368 acc *= 85;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 }
if (cap && cap < 4) {
Yuya Nishihara
base85: switch to policy importer
r32368 acc += 0xffffff >> (cap - 1) * 8;
Augie Fackler
cleanup: use clang-tidy to add missing {} around one-line statements...
r41367 }
Gregory Szorc
cext: move braces for control statements to same line...
r34438 for (j = 0; j < cap; j++) {
Yuya Nishihara
base85: switch to policy importer
r32368 acc = (acc << 8) | (acc >> 24);
*dst++ = acc;
}
}
return out;
Yuya Nishihara
base85: fix leak on error return from b85decode()...
r39483 bail:
Py_XDECREF(out);
return NULL;
Yuya Nishihara
base85: switch to policy importer
r32368 }
static char base85_doc[] = "Base85 Data Encoding";
static PyMethodDef methods[] = {
Augie Fackler
base85: allow clang-format oversight...
r36244 {"b85encode", b85encode, METH_VARARGS,
"Encode text in base85.\n\n"
"If the second parameter is true, pad the result to a multiple of "
"five characters.\n"},
{"b85decode", b85decode, METH_VARARGS, "Decode base85 text.\n"},
{NULL, NULL},
Yuya Nishihara
base85: switch to policy importer
r32368 };
static const int version = 1;
#ifdef IS_PY3K
static struct PyModuleDef base85_module = {
Augie Fackler
base85: allow clang-format oversight...
r36244 PyModuleDef_HEAD_INIT, "base85", base85_doc, -1, methods,
Yuya Nishihara
base85: switch to policy importer
r32368 };
PyMODINIT_FUNC PyInit_base85(void)
{
PyObject *m;
b85prep();
m = PyModule_Create(&base85_module);
PyModule_AddIntConstant(m, "version", version);
return m;
}
#else
PyMODINIT_FUNC initbase85(void)
{
PyObject *m;
m = Py_InitModule3("base85", methods, base85_doc);
b85prep();
PyModule_AddIntConstant(m, "version", version);
}
#endif