Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit simultaneous connections #316

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def parse_cli_args(cli_args=None):
"--max-manifest-size",
help="Maximum manifest file size allowed to load",
type=int,
default=manifest.MAX_MANIFEST_SIZE,
default=manifest.CheckerOptions.max_manifest_size,
)
parser.add_argument(
"--require-important-update",
Expand All @@ -399,6 +399,18 @@ def parse_cli_args(cli_args=None):
"This is useful to avoid PRs generated to update a singular unimportant source.",
action="store_true",
)
parser.add_argument(
"--max-connections",
help="""Maximum number of simultaneous connections""",
type=int,
default=manifest.CheckerOptions.conn_limit,
)
parser.add_argument(
"--max-connections-per-host",
help="""Maximum number of simultaneous connections per host""",
type=int,
default=manifest.CheckerOptions.conn_limit_per_host,
)

return parser.parse_args(cli_args)

Expand All @@ -413,6 +425,8 @@ async def run_with_args(args: argparse.Namespace) -> t.Tuple[int, int, bool]:
allow_unsafe=args.unsafe,
max_manifest_size=args.max_manifest_size,
require_important_update=args.require_important_update,
conn_limit=args.max_connections,
conn_limit_per_host=args.max_connections_per_host,
)

manifest_checker = manifest.ManifestChecker(args.manifest, options)
Expand Down
9 changes: 7 additions & 2 deletions src/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@

MAIN_SRC_PROP = "is-main-source"
IMPORTANT_SRC_PROP = "is-important"
MAX_MANIFEST_SIZE = 1024 * 100


log = logging.getLogger(__name__)
Expand All @@ -75,8 +74,10 @@ def find_appdata_file(directory, appid):
@dataclasses.dataclass(frozen=True)
class CheckerOptions:
allow_unsafe: bool = False
max_manifest_size: int = MAX_MANIFEST_SIZE
max_manifest_size: int = 1024 * 100
require_important_update: bool = False
conn_limit_per_host: int = 5
conn_limit: int = 50
Comment on lines +79 to +80
Copy link
Collaborator Author

@gasinvein gasinvein Jul 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nanonyme IIRC you were the one who previously suggested to limit simultaneousl connections to prevent upstreams from throttling us. Does this seem like a reasonable default?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gasinvein in general you're better off having one connection per backend and using HTTP keepalive. TLS handshakes are slow.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid 1 connection per host will be way too slow: in many apps, there are several sources from GitHub.



class ManifestChecker:
Expand Down Expand Up @@ -398,6 +399,10 @@ async def check(self, filter_type=None) -> t.List[ExternalBase]:
raise_for_status=True,
headers=HTTP_CLIENT_HEADERS,
timeout=aiohttp.ClientTimeout(connect=TIMEOUT_CONNECT, total=TIMEOUT_TOTAL),
connector=aiohttp.TCPConnector(
limit=self.opts.conn_limit,
limit_per_host=self.opts.conn_limit_per_host,
),
) as http_session:
check_tasks = []
for data in external_data:
Expand Down