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

*: support for limiting the number of client connections #14409

Merged
merged 6 commits into from
Jan 15, 2020

Conversation

zimulala
Copy link
Contributor

@zimulala zimulala commented Jan 9, 2020

What problem does this PR solve?

Limiting the number of connections is to control that there should not be too many connections on a single server, resulting in resource occupation. This feature is similar to max_connections in MySQL, but it only controls the current server.

What is changed and how it works?

Adds a check on the connection count when a connection is established.

Check List

Tests

  • unit test

Code changes

  • Has interface methods change

Release note

  • Support for limiting the number of client connections

Copy link
Contributor

@crazycs520 crazycs520 left a comment

Choose a reason for hiding this comment

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

LGTM

config/config.go Outdated
@@ -477,6 +479,7 @@ var defaultConf = Config{
SplitRegionMaxNum: 1000,
RepairMode: false,
RepairTableList: []string{},
MaxConnections: 151,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why 151?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's 151 in our original code and in MySQL.

Copy link

Choose a reason for hiding this comment

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

The reason is historical. When the apache default was 150, and MySQL was 100, there were cases where web pages would contain too many connection errors. MySQL raised its limit to Apache's +1. It does not necessarily need to be followed literally.

@zimulala zimulala added the status/LGT1 Indicates that a PR has LGTM 1. label Jan 9, 2020
Copy link
Member

@jackysp jackysp left a comment

Choose a reason for hiding this comment

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

LGTM

@jackysp jackysp added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jan 9, 2020
@wwar
Copy link

wwar commented Jan 14, 2020

This has an important behavior difference from MySQL, which is that in MySQL the max_connections cap only applies to regular users. There will always be an extra connection for super privileged users so that an administrator can log in and kill connections if there has been a thundering herd problem.

In MySQL 8.0 this was extended to provide a separate admin port, which is a better implementation: https://dev.mysql.com/worklog/task/?id=12138

Copy link
Member

@jackysp jackysp left a comment

Choose a reason for hiding this comment

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

Hold on.

config/config.go Outdated Show resolved Hide resolved
@jackysp
Copy link
Member

jackysp commented Jan 14, 2020

This has an important behavior difference from MySQL, which is that in MySQL the max_connections cap only applies to regular users. There will always be an extra connection for super privileged users so that an administrator can log in and kill connections if there has been a thundering herd problem.

In MySQL 8.0 this was extended to provide a separate admin port, which is a better implementation: https://dev.mysql.com/worklog/task/?id=12138

Yes, it maybe works like the extra port in MariaDB or Percona. We could discuss it in another issue.

@coocood
Copy link
Member

coocood commented Jan 14, 2020

The connection limit applies to a single server, I think put it into the config file is better.

@jackysp
Copy link
Member

jackysp commented Jan 14, 2020

The connection limit applies to a single server, I think put it into the config file is better.

OK, it is better to use a different name, e.g. server-max-connections

@zimulala zimulala changed the title *: support for max_connections *: support for limiting the number of client connections Jan 15, 2020
@zimulala
Copy link
Contributor Author

zimulala commented Jan 15, 2020

@coocood @jackysp PTAL. I update it as a new config variable.

config/config.go Outdated
@@ -477,6 +479,7 @@ var defaultConf = Config{
SplitRegionMaxNum: 1000,
RepairMode: false,
RepairTableList: []string{},
MaxServerConnections: 1024,
Copy link
Member

@coocood coocood Jan 15, 2020

Choose a reason for hiding this comment

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

I think set it higher like 4096 is better for compatibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. PTAL @coocood

@coocood
Copy link
Member

coocood commented Jan 15, 2020

LGTM

@jackysp
Copy link
Member

jackysp commented Jan 15, 2020

/merge

@sre-bot sre-bot added the status/can-merge Indicates a PR has been approved by a committer. label Jan 15, 2020
@sre-bot
Copy link
Contributor

sre-bot commented Jan 15, 2020

/run-all-tests

@sre-bot sre-bot merged commit d65e23f into pingcap:master Jan 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/server status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants