gpt4 book ai didi

android - ReSTLet 一遍又一遍地重启内部 http 客户端

转载 作者:搜寻专家 更新时间:2023-11-01 09:07:33 25 4
gpt4 key购买 nike

我将 ReSTLet 2.1 RC 4 与 org.reSTLet.ext.httpclientorg.reSTLet.ext.jacksonorg.reSTLet.ext 一起使用。 json 从远程服务器获取数据。然而,对于仅 6 个对象,通过房屋内的无线数据连接需要 6 秒。

如您所见,除了 GC 之外还有许多消息,例如 Starting the internal [HTTP/1.1] clientStopping the internal [HTTP/1.1] client。这对应于需要花费大量时间的大型 GC。

06-01 03:21:46.913: RestletTrip(2653): Querying: [SOMEURL/SOMENUMBER]
06-01 03:21:46.933: I/org.restlet(2653): Starting the internal [HTTP/1.1] client
06-01 03:21:47.053: D/dalvikvm(2653): GC_CONCURRENT freed 708K, 34% free 9214K/13831K, external 576K/1020K, paused 3ms+3ms
06-01 03:21:47.053: I/org.restlet(2653): Stopping the internal[HTTP/1.1] client
06-01 03:21:47.103: D/dalvikvm(2653): GC_FOR_MALLOC freed 4924K, 61% free 5523K/13831K, external 576K/1020K, paused 31ms
06-01 03:21:47.173: D/dalvikvm(2653): GC_CONCURRENT freed 95K, 53% free 6574K/13831K, external 576K/1020K, paused 2ms+3ms
06-01 03:21:47.253: D/dalvikvm(2653): GC_CONCURRENT freed 46K, 43% free 8012K/13831K, external 576K/1020K, paused 2ms+3ms
06-01 03:21:47.734: I/global(2653): Loaded time zone names for en_US in 397ms.
06-01 03:21:48.014: RestletTrip(2653): Querying: [SOMEURL/SOMENUMBER]
06-01 03:21:48.124: D/dalvikvm(2653): GC_CONCURRENT freed 1225K, 38% free 8688K/13831K, external 576K/1020K, paused 3ms+3ms
06-01 03:21:48.124: I/org.restlet(2653): Stopping the internal[HTTP/1.1] client
06-01 03:21:48.134: I/org.restlet(2653): Starting the internal [HTTP/1.1] client
06-01 03:21:48.184: D/dalvikvm(2653): GC_FOR_MALLOC freed 5022K, 62% free 5341K/13831K, external 576K/1020K, paused 31ms
06-01 03:21:48.244: D/dalvikvm(2653): GC_CONCURRENT freed 96K, 55% free 6307K/13831K, external 576K/1020K, paused 2ms+3ms
06-01 03:21:48.314: D/dalvikvm(2653): GC_CONCURRENT freed 44K, 45% free 7663K/13831K, external 576K/1020K, paused 3ms+4ms
06-01 03:21:48.795: I/global(2653): Loaded time zone names for en_US in 405ms.
06-01 03:21:49.015: D/dalvikvm(2653): GC_CONCURRENT freed 695K, 37% free 8736K/13831K, external 576K/1020K, paused 3ms+3ms
06-01 03:21:49.155: RestletTrip(2653): Querying: [SOMEURL/SOMENUMBER]
06-01 03:21:49.165: I/org.restlet(2653): Starting the internal [HTTP/1.1] client
06-01 03:21:49.225: D/dalvikvm(2653): GC_FOR_MALLOC freed 672K, 30% free 9778K/13831K, external 576K/1020K, paused 34ms
06-01 03:21:49.225: I/org.restlet(2653): Stopping the internal[HTTP/1.1] client
06-01 03:21:49.265: D/dalvikvm(2653): GC_FOR_MALLOC freed 4902K, 61% free 5637K/14343K, external 576K/1020K, paused 32ms
06-01 03:21:49.325: D/dalvikvm(2653): GC_CONCURRENT freed 97K, 54% free 6703K/14343K, external 576K/1020K, paused 3ms+4ms
06-01 03:21:49.395: D/dalvikvm(2653): GC_CONCURRENT freed 54K, 44% free 8167K/14343K, external 576K/1020K, paused 3ms+3ms
06-01 03:21:49.876: I/global(2653): Loaded time zone names for en_US in 407ms.
06-01 03:21:50.136: RestletTrip(2653): Querying: [SOMEURL/SOMENUMBER]
06-01 03:21:50.156: I/org.restlet(2653): Starting the internal [HTTP/1.1] client
06-01 03:21:50.236: D/dalvikvm(2653): GC_CONCURRENT freed 1295K, 38% free 8905K/14343K, external 576K/1020K, paused 3ms+4ms
06-01 03:21:50.236: I/org.restlet(2653): Stopping the internal[HTTP/1.1] client
06-01 03:21:50.286: D/dalvikvm(2653): GC_FOR_MALLOC freed 4991K, 61% free 5636K/14343K, external 576K/1020K, paused 32ms
06-01 03:21:50.346: D/dalvikvm(2653): GC_CONCURRENT freed 52K, 53% free 6748K/14343K, external 576K/1020K, paused 2ms+4ms
06-01 03:21:50.386: D/dalvikvm(2653): GC_FOR_MALLOC freed 50K, 43% free 8249K/14343K, external 576K/1020K, paused 30ms
06-01 03:21:50.867: I/global(2653): Loaded time zone names for en_US in 400ms.
06-01 03:21:51.107: RestletTrip(2653): Querying: [SOMEURL/SOMENUMBER]
06-01 03:21:51.127: I/org.restlet(2653): Starting the internal [HTTP/1.1] client
06-01 03:21:51.207: D/dalvikvm(2653): GC_CONCURRENT freed 1290K, 38% free 9006K/14343K, external 576K/1020K, paused 2ms+4ms
06-01 03:21:51.207: I/org.restlet(2653): Stopping the internal[HTTP/1.1] client
06-01 03:21:51.257: D/dalvikvm(2653): GC_FOR_MALLOC freed 4937K, 60% free 5791K/14343K, external 576K/1020K, paused 32ms
06-01 03:21:51.317: D/dalvikvm(2653): GC_CONCURRENT freed 106K, 52% free 6900K/14343K, external 576K/1020K, paused 2ms+4ms
06-01 03:21:51.387: D/dalvikvm(2653): GC_CONCURRENT freed 54K, 42% free 8448K/14343K, external 576K/1020K, paused 3ms+4ms
06-01 03:21:51.868: I/global(2653): Loaded time zone names for en_US in 406ms.
06-01 03:21:52.118: RestletTrip(2653): Querying: [SOMEURL/SOMENUMBER]
06-01 03:21:52.128: I/org.restlet(2653): Starting the internal [HTTP/1.1] client
06-01 03:21:52.218: D/dalvikvm(2653): GC_CONCURRENT freed 1297K, 36% free 9198K/14343K, external 576K/1020K, paused 3ms+3ms
06-01 03:21:52.218: I/org.restlet(2653): Stopping the internal[HTTP/1.1] client

我使用的代码是(为便于理解而删除):

public List<Trip> getTrips() {

// All the ids for the different trips
List<Long> ids = new ArrayList<Long>;
ids.add(new Long(14));
ids.add(new Long(45));
ids.add(new Long(34));
ids.add(new Long(11));
ids.add(new Long(33));
ids.add(new Long(17));

// All the Trips
List<Trip> result = new ArrayList<Trip>();

for (Long tripID : ids) {
Trip trip = getTrip(tripID);

// Add trip to the list
if (trip != null) {
result.add(trip);
}
}
return result;
}

public Trip getTrip(ISettings settings, Long tripID) throws GetTripException, NoSuchElementException {

// Create resource
final TripsResource tripResource = getClientResource(ServerPaths.getTrip(tripID), TripsResource.class);

// Get trip from server
return tripResource.getTrip();
}

我使用的引擎设置是

import org.restlet.engine.Engine;
import org.restlet.ext.httpclient.HttpClientHelper;
import org.restlet.ext.jackson.JacksonConverter;
import org.restlet.ext.json.JsonConverter;
import org.restlet.Client;
import org.restlet.data.Protocol;

protected void setupEngine() {
final Engine engine = Engine.getInstance();

engine.getRegisteredClients().add(new HttpClientHelper(new Client(Protocol.HTTP)));
engine.getRegisteredConverters().add(new JacksonConverter());
engine.getRegisteredConverters().add(new JsonConverter());
}

因此,由于 GC,检索速度很慢。我怎样才能提高性能?

最佳答案

您确实在一遍又一遍地重新创建 HTTP 客户端连接器。

解决方案是创建一个实例:myClient = new Client(Protocol.HTTP);

然后,通过 myClientResource.setNext(myClient); 为您创建的每个 ClientResource 设置它;

顺便说一句,如果您使用的是父 ReSTLet 组件和应用程序,这会自动为您完成。

关于android - ReSTLet 一遍又一遍地重启内部 http 客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10843426/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com