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

Dubbo-2013 #2114

Merged
merged 15 commits into from
Jul 25, 2018
Merged
Show file tree
Hide file tree
Changes from 14 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
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public class ConsumerConfig extends AbstractReferenceConfig {
// networking framework client uses: netty, mina, etc.
private String client;

// client thread pool type: cached, fixed, limit, eager
private String threadpool;

@Override
public void setTimeout(Integer timeout) {
super.setTimeout(timeout);
Expand All @@ -56,4 +59,12 @@ public String getClient() {
public void setClient(String client) {
this.client = client;
}

public String getThreadpool() {
return threadpool;
}

public void setThreadpool(String threadpool) {
this.threadpool = threadpool;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,11 @@ public void testClient() throws Exception {
consumer.setClient("client");
assertThat(consumer.getClient(), equalTo("client"));
}

@Test
public void testThreadpool() throws Exception {
ConsumerConfig consumer = new ConsumerConfig();
consumer.setThreadpool("fixed");
assertThat(consumer.getThreadpool(), equalTo("fixed"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,11 @@
<xsd:documentation><![CDATA[ Transporter layer framework: netty mina.... ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="threadpool" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ Consumer threadpool: cached, fixed, limited, eager]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
Copy link
Contributor

Choose a reason for hiding this comment

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

We may also need the following two parameters:

                <xsd:attribute name="threads" type="xsd:string" use="optional">
                    <xsd:annotation>
                        <xsd:documentation><![CDATA[ The thread pool size. ]]></xsd:documentation>
                    </xsd:annotation>
                </xsd:attribute>
                <xsd:attribute name="queues" type="xsd:string" use="optional">
                    <xsd:annotation>
                        <xsd:documentation><![CDATA[ The thread pool queue size. ]]></xsd:documentation>
                    </xsd:annotation>
                </xsd:attribute>

Copy link
Contributor

Choose a reason for hiding this comment

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

<xsd:anyAttribute namespace="##other" processContents="lax"/>
</xsd:extension>
</xsd:complexContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.store.DataStore;
import org.apache.dubbo.common.utils.ExecutorUtil;
import org.apache.dubbo.common.utils.NamedThreadFactory;
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.common.utils.*;
import org.apache.dubbo.remoting.Channel;
import org.apache.dubbo.remoting.ChannelHandler;
import org.apache.dubbo.remoting.Client;
Expand Down Expand Up @@ -113,7 +111,12 @@ public AbstractClient(URL url, ChannelHandler handler) throws RemotingException

protected static ChannelHandler wrapChannelHandler(URL url, ChannelHandler handler) {
url = ExecutorUtil.setThreadName(url, CLIENT_THREAD_POOL_NAME);
url = url.addParameterIfAbsent(Constants.THREADPOOL_KEY, Constants.DEFAULT_CLIENT_THREADPOOL);
String key = Constants.DEFAULT_KEY + Constants.HIDE_KEY_PREFIX + Constants.THREADPOOL_KEY;
String threadpool = url.getParameter(key);
if (StringUtils.isNotEmpty(threadpool)) {
url = url.removeParameter(key);
}
url = url.addParameterIfAbsent(Constants.THREADPOOL_KEY, StringUtils.isNotEmpty(threadpool) ? threadpool : Constants.DEFAULT_CLIENT_THREADPOOL);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to change the code here?
I think we will have default.threadpool key in automatically.

Copy link
Contributor Author

@tswstarplanet tswstarplanet Jul 24, 2018

Choose a reason for hiding this comment

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

@chickenlj Ok, because I found that when ReferenceConfig integrate the configuration of ConsumerConfig, it will add the prefix "default.", so the "threadpool" property of <dubbo:consumer ../> will change to "default.thread" parameter in the URL.
So, I think we have two ways to optimize the issue.
First, take some special process when integrate the "threadpool" property of ConsumerConfig to ReferenceConfig to wipe off the prefix "default.";
Second is just the method that this sumbit uses.
If the second way is not so good, I think we can take the second one.

Copy link
Contributor

Choose a reason for hiding this comment

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

Look at the getParameter("threadpool") logic in URL, it will: first check "threadpool" and then check "default.threadpool"

https://github.com/apache/incubator-dubbo/blob/0b6e6f3a375d82aab1a1f17b034e666c63f61103/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java#L421

return ChannelHandlers.wrap(handler, url);
}

Expand Down