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

Missing connection pool events from client built by RxContexts constructs #172

Closed
allenxwang opened this issue Jul 3, 2014 · 1 comment
Labels
Milestone

Comments

@allenxwang
Copy link

Here is the JUnit test case that shows connection count is not incremented after a successful connection to www.google.com:

    @Test
    public void testConnectionPoolMetrics() {
        HttpClientBuilder<ByteBuf, ByteBuf> builder = RxContexts.newHttpClientBuilder("www.google.com", 80, RxContexts.DEFAULT_CORRELATOR);
        HttpClient<ByteBuf, ByteBuf> client = builder.withConnectionPoolLimitStrategy(new CompositePoolLimitDeterminationStrategy(
                new MaxConnectionsBasedStrategy(100), new MaxConnectionsBasedStrategy(100))).build();
        HttpClientListener listener = HttpClientListener.newHttpListener("default");
        client.subscribe(listener);
        HttpClientRequest<ByteBuf> request = HttpClientRequest.createGet("/");
        String result = client.submit(request).flatMap(new Func1<HttpClientResponse<ByteBuf>, Observable<ByteBuf>>(){
            @Override
            public Observable<ByteBuf> call(HttpClientResponse<ByteBuf> t1) {
                return t1.getContent();
            }
        }).map(new Func1<ByteBuf, String>(){
            @Override
            public String call(ByteBuf t1) {
                return t1.toString(Charset.defaultCharset());
            }
        }).toBlocking().single();
        System.out.println(listener.getConnectionCount());
        System.out.println(listener.getPoolAcquires());
    }

It prints out zero for both counts.

The poolAquires metric is wrong because of a typo in HttpClientListener:

         @Override
         protected void onPoolAcquireSuccess(long duration, TimeUnit timeUnit) {
            HttpClientListener.this.onPoolReleaseSuccess(duration, timeUnit); // wrong API called
         }

However, it seems that the connection count problem is caused by no listeners added to ClientChannelFactoryImpl.eventsSubject, after RxContexts.withChannelFactory() is called in RxContexts constructs.

NiteshKant pushed a commit to NiteshKant/RxNetty that referenced this issue Jul 4, 2014
The client connection factory created by RxContexts was not having the reference to the eventsubject.
This made the connection factory create a fresh subject.
Fixed the same and added the testcase for this.
@NiteshKant NiteshKant added this to the 0.3.8 milestone Jul 4, 2014
@NiteshKant NiteshKant added the bug label Jul 4, 2014
@NiteshKant NiteshKant self-assigned this Jul 4, 2014
NiteshKant added a commit that referenced this issue Jul 4, 2014
@NiteshKant
Copy link
Member

Thanks @allenxwang for finding the issue.

The problem was that the client connection factory created by RxContexts was not having the reference to the eventsubject.This made the connection factory create a fresh subject.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants