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

[SCB-687] add highway server connection protection #824

Merged
merged 3 commits into from
Aug 1, 2018

Conversation

zhengyangyong
Copy link

@zhengyangyong zhengyangyong commented Jul 20, 2018

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a JIRA issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a JIRA issue. Your pull request should address just this issue, without pulling in other changes.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [SCB-XXX] Fixes bug in ApproximateQuantiles, where you replace SCB-XXX with the appropriate JIRA issue.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean install to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

Add servicecomb.highway.server.connection-limit for setting this limit
Default value is Integer.MAX_VALUE

eclipse-vertx/vert.x#2542

@coveralls
Copy link

coveralls commented Jul 20, 2018

Coverage Status

Coverage decreased (-0.03%) to 87.055% when pulling 2c17acd on zhengyangyong:SCB-687 into 8227f0c on apache:master.

@@ -57,8 +69,18 @@ public void init(Vertx vertx, String sslKey, AsyncResultCallback<InetSocketAddre
}

netServer.connectHandler(netSocket -> {
TcpServerConnection connection = createTcpServerConnection();
connection.init(netSocket);
if (connectedCounter.get() < connectionLimit) {
Copy link
Contributor

Choose a reason for hiding this comment

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

seems this is more clear.

if (connectedCounter.incrementAndGet() > connectionLimit){
  connectedCounter.decrementAndGet();
  netSocket.close();
  return;
}

TcpServerConnection connection = createTcpServerConnection();
connection.init(netSocket, connectedCounter);
EventManager.post(new ClientConnectedEvent(netSocket, connectedCount));

Copy link
Author

Choose a reason for hiding this comment

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

Done

import io.vertx.core.Vertx;
import io.vertx.core.net.NetServer;
import io.vertx.core.net.NetServerOptions;

public class TcpServer {
private URIEndpointObject endpointObject;

private final AtomicInteger connectedCounter;
Copy link
Contributor

Choose a reason for hiding this comment

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

TcpServer will be created for each HighwayServerVerticle instance
so the counter number in server is not correct.

Copy link
Author

Choose a reason for hiding this comment

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

your means I need move it to HighwayServerVerticle instance?

Copy link
Author

Choose a reason for hiding this comment

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

I think we only deploy one HighwayServerVerticle instance (as a spring bean), so may not problem ?

Copy link
Contributor

Choose a reason for hiding this comment

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

if serivcecomb.highway.thread-count is n, then HighwayServerVerticle instance count is n

Copy link
Author

Choose a reason for hiding this comment

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

sorry, forgotten

Copy link
Author

Choose a reason for hiding this comment

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

Done

# See the License for the specific language governing permissions and
# limitations under the License.
#
log4j.rootLogger=INFO, stdout
Copy link
Contributor

Choose a reason for hiding this comment

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

new projects switch to logback?

Copy link
Author

@zhengyangyong zhengyangyong Jul 20, 2018

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

already depend on pojo-test jar, can remove this file

highway:
address: 0.0.0.0:7070
server:
connection-limit: 0
Copy link
Contributor

Choose a reason for hiding this comment

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

consider dynamic update?

Copy link
Author

Choose a reason for hiding this comment

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

I think it is not necessary yet

Copy link
Contributor

Choose a reason for hiding this comment

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

discuss with customers, we should support this.

Copy link
Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

Choose a reason for hiding this comment

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

already depend on pojo-test jar
and you want to reuse it's declare

so only need to append new config items, no need to declare everything again.

return counters;
}

@Subscribe
Copy link
Contributor

Choose a reason for hiding this comment

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

all eventloop thread will sync invoke this
it's not a good sample.

Copy link
Contributor

Choose a reason for hiding this comment

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

what's this watcher purpose?

Copy link
Author

Choose a reason for hiding this comment

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

only for test

Assert.assertArrayEquals("check connection count change", new Integer[] {1, 0}, watcher.getCounters().toArray());

watcher will receive a connection connected event when consumer calling
event.getTotalConnectedCount() = 1
and when

SCBEngine.getInstance().destroy();

watcher will receive a connection close event
event.getTotalConnectedCount() = 0

Signed-off-by: zhengyangyong <yangyong.zheng@huawei.com>
…pdate

Signed-off-by: zhengyangyong <yangyong.zheng@huawei.com>
@@ -17,6 +17,9 @@

package org.apache.servicecomb.foundation.vertx;

/**
Copy link
Contributor

Choose a reason for hiding this comment

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

indentation is one space?
also need to check other codes.

Copy link
Author

Choose a reason for hiding this comment

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

I copy before, and I am using GoogleStyle in etc

Copy link
Contributor

Choose a reason for hiding this comment

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

sorry, i made a mistake caused by the char "+"

@@ -17,7 +17,7 @@

APPLICATION_ID: pojotest-it
service_description:
name: pojo-connection-limit
name: pojo
Copy link
Contributor

Choose a reason for hiding this comment

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

conflict with integration-tests/pojo-test

Copy link
Author

Choose a reason for hiding this comment

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

I think no problem,also reused

PojoService.hello.SayHello("whatever");

in pojo-test but need add servicecomb.highway.server.onnection-limit setting

Copy link
Contributor

Choose a reason for hiding this comment

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

at last, we will move integration test to real SC, not a mock SC, your logic will cause conflict in that time.

public class PojoSpringMain {

public static void main(final String[] args) {
SpringApplication.run(PojoSpringMain.class, args);
Copy link
Contributor

Choose a reason for hiding this comment

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

already depend on pojo-test jar
just invoke org.apache.servicecomb.demo.pojo.test.PojoTestMain
no need to depend on complex springboot

Copy link
Author

Choose a reason for hiding this comment

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

Done

Signed-off-by: zhengyangyong <yangyong.zheng@huawei.com>
@liubao68 liubao68 merged commit 0e8664d into apache:master Aug 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants