Skip to content

Commit 0f7ec56

Browse files
authored
Merge pull request #465 from YangSen-qn/dns_add_server_ip
optimize prefetch dns
2 parents 2da0f9e + 239a52a commit 0f7ec56

34 files changed

+534
-277
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
#Changelog
2+
## 8.3.2(2021-08-09)
3+
* dns 缓存增加最大有效时间配置
4+
* 网络状态检测可关闭
5+
6+
27
## 8.3.1(2021-07-12)
38
* 兼容支持 Android 4.x ( API level 14+ ),使用 Android4.x 对应 okhttp 版本请调整至 3.12.+
49
* 支持 okhttp 4.9

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ https://github.com/qiniudemo/qiniu-lab-android
3131
| 7.0.7 | Android 2.2+ | android-async-http 1.4.8 |
3232

3333
### 注意
34-
* 推荐使用最新版:8.3.1
34+
* 推荐使用最新版:8.3.2
3535
* AndroidNetwork.getMobileDbm()可以获取手机信号强度,需要如下权限(API>=18时生效)
3636
```
3737
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

library/src/androidTest/java/com/qiniu/android/CancelTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void testFile() throws Throwable {
4848
}
4949

5050
public void testMultiFile() throws Throwable {
51-
Temp[] ts = new Temp[]{templateFile(400, 0.2), templateFile(700, 0.2), templateFile(1024, 0.51), templateFile(4 * 1024, 0.5), templateFile(8 * 1024 + 1, 0.6)};
51+
Temp[] ts = new Temp[]{templateFile(400, 0.01), templateFile(700, 0.02), templateFile(1024, 0.02), templateFile(4 * 1024, 0.02), templateFile(8 * 1024 + 1, 0.2)};
5252
checkTemp(ts, "testFile");
5353
}
5454

library/src/androidTest/java/com/qiniu/android/ConcurrentResumeUploadTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public void testReuploadV1() {
102102
String key = "android_concurrent_resume_reupload_v1_" + size + "k";
103103
try {
104104
File file = TempFile.createFile(size, key);
105-
reuploadUploadTest((long) (size * 0.7), file, key, configuration, null);
105+
reuploadUploadTest((long) (size * 0.5), file, key, configuration, null);
106106
TempFile.remove(file);
107107
} catch (IOException e) {
108108
e.printStackTrace();

library/src/androidTest/java/com/qiniu/android/ResumeUploadTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public void testReuploadV1() {
102102
String key = "android_resume_reupload_v1_" + size + "k";
103103
try {
104104
File file = TempFile.createFile(size, key);
105-
reuploadUploadTest((long) (size * 0.7), file, key, configuration, null);
105+
reuploadUploadTest((long) (size * 0.5), file, key, configuration, null);
106106
TempFile.remove(file);
107107
} catch (IOException e) {
108108
e.printStackTrace();

library/src/androidTest/java/com/qiniu/android/TestFileRecorder.java

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,23 +148,37 @@ public boolean shouldWait() {
148148
TempFile.remove(tempFile);
149149
}
150150

151-
public void test_600k() throws Throwable {
152-
template(600, 0.7);
151+
public void test_4M1K() throws Throwable {
152+
template(4 * 1024 + 1, 0.5);
153+
153154
}
154155

155-
public void test700k() throws Throwable {
156-
template(700, 0.1);
156+
public void test5M() throws Throwable {
157+
template(5 * 1024, 0.51);
157158
}
158159

159-
public void test1M() throws Throwable {
160-
template(1024, 0.51);
160+
public void test_5M1K() throws Throwable {
161+
template(5 * 1024 + 1, 0.5);
162+
161163
}
162164

163-
public void test_4M1K() throws Throwable {
164-
template(4 * 1024 + 1, 0.5);
165+
public void test8M() throws Throwable {
166+
template(8 * 1024, 0.51);
167+
}
168+
169+
public void test_8M1K() throws Throwable {
170+
template(8 * 1024 + 1, 0.5);
171+
172+
}
165173

174+
public void test10M() throws Throwable {
175+
template(10 * 1024, 0.51);
166176
}
167177

178+
public void test_10M1K() throws Throwable {
179+
template(10 * 1024 + 1, 0.5);
180+
181+
}
168182

169183
public void testLastModify() throws IOException {
170184
File f = File.createTempFile("qiniutest", "b");

library/src/main/java/com/qiniu/android/collect/ReportItem.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public String toJson(){
8282
public static final String RequestKeyPrefetchedBefore = "prefetched_before";
8383
public static final String RequestKeyPrefetchedErrorMessage = "prefetched_error_message";
8484
public static final String RequestKeyNetworkMeasuring = "network_measuring";
85+
public static final String RequestKeyPerceptiveSpeed = "perceptive_speed";
8586

8687
// 分块上传统计⽇志
8788
public static final String BlockKeyLogType = "log_type";
@@ -102,6 +103,7 @@ public String toJson(){
102103
public static final String BlockKeyOsVersion = "os_version";
103104
public static final String BlockKeySDKName = "sdk_name";
104105
public static final String BlockKeySDKVersion = "sdk_version";
106+
public static final String BlockKeyPerceptiveSpeed = "perceptive_speed";
105107

106108

107109
// 上传质量统计
@@ -113,6 +115,7 @@ public String toJson(){
113115
public static final String QualityKeyTotalElapsedTime = "total_elapsed_time";
114116
public static final String QualityKeyRequestsCount = "requests_count";
115117
public static final String QualityKeyRegionsCount = "regions_count";
118+
public static final String QualityKeyFileSize = "file_size";
116119
public static final String QualityKeyBytesSent = "bytes_sent";
117120
public static final String QualityKeyCloudType = "cloud_type";
118121
public static final String QualityKeyErrorType = "error_type";
@@ -121,6 +124,7 @@ public String toJson(){
121124
public static final String QualityKeyOsVersion = "os_version";
122125
public static final String QualityKeySDKName = "sdk_name";
123126
public static final String QualityKeySDKVersion = "sdk_version";
127+
public static final String QualityKeyPerceptiveSpeed = "perceptive_speed";
124128

125129
public static String requestReportStatusCode(ResponseInfo responseInfo){
126130
if (responseInfo == null){

library/src/main/java/com/qiniu/android/common/AutoZone.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.qiniu.android.common;
22

33
import com.qiniu.android.http.ResponseInfo;
4+
import com.qiniu.android.http.dns.DnsPrefetchTransaction;
45
import com.qiniu.android.http.request.RequestTransaction;
56
import com.qiniu.android.http.metrics.UploadRegionRequestMetrics;
67
import com.qiniu.android.storage.UpToken;
@@ -44,6 +45,14 @@ public List<String> getUcServerList() {
4445
}
4546
}
4647

48+
private String[] getUcServerArray() {
49+
if (ucServer != null) {
50+
return new String[]{ucServer};
51+
} else {
52+
return new String[]{Config.preQueryHost00, Config.preQueryHost01};
53+
}
54+
}
55+
4756
@Override
4857
public ZonesInfo getZonesInfo(UpToken token) {
4958
if (token == null) {
@@ -75,6 +84,7 @@ public void preQuery(final UpToken token, final QueryHandler completeHandler) {
7584
return;
7685
}
7786

87+
DnsPrefetchTransaction.addDnsCheckAndPrefetchTransaction(getUcServerArray());
7888

7989
try {
8090
SingleFlight.perform(cacheKey, new SingleFlight.ActionHandler() {

library/src/main/java/com/qiniu/android/common/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
public final class Constants {
5-
public static final String VERSION = "8.3.1";
5+
public static final String VERSION = "8.3.2";
66

77
public static final String UTF_8 = "utf-8";
88
}

library/src/main/java/com/qiniu/android/http/connectCheck/ConnectChecker.java

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@
1212

1313
import org.json.JSONObject;
1414

15+
import java.util.concurrent.Callable;
16+
import java.util.concurrent.Executors;
17+
import java.util.concurrent.ScheduledExecutorService;
18+
import java.util.concurrent.TimeUnit;
19+
1520
public class ConnectChecker {
1621

22+
private static ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
1723
private static SingleFlight<UploadSingleRequestMetrics> singleFlight = new SingleFlight<>();
1824

1925
public static boolean isConnected(UploadSingleRequestMetrics metrics) {
@@ -81,9 +87,6 @@ public void complete(UploadSingleRequestMetrics metrics) {
8187
synchronized (checkStatus) {
8288
checkStatus.completeCount += 1;
8389
}
84-
if (isHostConnected) {
85-
checkStatus.isConnected = true;
86-
}
8790
if (isHostConnected || checkStatus.completeCount == checkStatus.totalCount) {
8891
synchronized (checkStatus) {
8992
if (checkStatus.isCompleted) {
@@ -106,13 +109,40 @@ public void complete(UploadSingleRequestMetrics metrics) {
106109

107110
private static void checkHost(final String host, final CheckCompleteHandler completeHandler) {
108111

109-
Request request = new Request(host, Request.HttpMethodHEAD, null, null, GlobalConfiguration.getInstance().connectCheckTimeout);
112+
final boolean[] hasCallback = {false};
113+
int timeout = GlobalConfiguration.getInstance().connectCheckTimeout;
114+
115+
final UploadSingleRequestMetrics timeoutMetrics = new UploadSingleRequestMetrics();
116+
timeoutMetrics.start();
117+
executorService.schedule(new Callable<Object>() {
118+
@Override
119+
public Object call() throws Exception {
120+
synchronized (this) {
121+
if (hasCallback[0]) {
122+
return null;
123+
}
124+
hasCallback[0] = true;
125+
}
126+
timeoutMetrics.end();
127+
completeHandler.complete(timeoutMetrics);
128+
return null;
129+
}
130+
}, timeout, TimeUnit.SECONDS);
131+
132+
Request request = new Request(host, Request.HttpMethodHEAD, null, null, timeout);
110133
SystemHttpClient client = new SystemHttpClient();
111134

112135
LogUtil.i("== checkHost:" + host);
113136
client.request(request, true, null, null, new IRequestClient.RequestClientCompleteHandler() {
114137
@Override
115138
public void complete(ResponseInfo responseInfo, UploadSingleRequestMetrics metrics, JSONObject response) {
139+
synchronized (this) {
140+
if (hasCallback[0]) {
141+
return;
142+
}
143+
hasCallback[0] = true;
144+
}
145+
116146
LogUtil.i("== checkHost:" + host + " responseInfo:" + responseInfo);
117147
completeHandler.complete(metrics);
118148
}
@@ -128,7 +158,6 @@ private static class CheckStatus {
128158
private int totalCount = 0;
129159
private int completeCount = 0;
130160
private boolean isCompleted = false;
131-
private boolean isConnected = false;
132161
}
133162

134163
private static class CheckResult {

0 commit comments

Comments
 (0)