Using HttpClient

Questions and answers on developing, deploying and using plugins and JavaBeans

Using HttpClient

Postby rieder » Thu Jun 01, 2023 8:08 am

Hi

How should the http client be used? We try to call PUT Requests and notice problems after a while. The Server does not receive the calls, they hang. Or we see and error in the log, saying "Socket closed".
  • We have no timeout defined.
  • We use asynchronous calls.
  • We create the http client once and reuse it. Is there a state we can check?
  • We create a new put request for each call.
  • We have two methods, which call put requests. We use the same success handlers and error handlers for both.
Can anyone point us to the right usage of the http client?

Thank you and kind regards
Birgit
Birgit Rieder
7r AG, Switzerland
SAN Developer
http://www.seven-r.ch
User avatar
rieder
 
Posts: 177
Joined: Thu Jan 26, 2012 5:18 pm

Re: Using HttpClient

Postby robert.edelmann » Thu Jun 01, 2023 9:32 am

We use the http-client mostly for GET-Requests, but we always close the client as soon as possible, mainly to avoid problems with thread-/ memory-usage, we used to have a loop that opened many clients, which after an update to 2022.09 basically brought the our server to its limits.

So it's basically open client - request - get data / status - close.

But i'm interested how other people do this, perhaps there's an more efficient way.
mit freundlichen Grüßen
Robert Stefan Edelmann
User avatar
robert.edelmann
 
Posts: 94
Joined: Wed Aug 14, 2013 6:12 pm

Re: Using HttpClient

Postby jcompagner » Thu Jun 01, 2023 11:28 am

you can reuse 1 http client just fine
If you know a servoy client needs an http client frequently you can cache it and use it
Dont' start constant clients that you don't close that is a big nogo.


if there is never a success or error callback method called, then for some reason the server doesn't respond (but does accept the request)
So not sure what happens at the caller side? are success and error never called?

there are limits how many request the http plugin does at 1 time at the same time.
see for example:

var config = plugins.http.createNewHttpClientConfig();
config.maxIOThreadCount = 5;

also with http://httpbin.org/#/Anything you can test stuff
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: Using HttpClient

Postby rieder » Thu Jun 01, 2023 4:17 pm

Thank you, Robert and Johan

With your answers I could (as far as I can tell so far) get it to work stable.
  • As you, Johan, mentioned: Creating a client each time does not work.
  • Closing the client in a callback method is a problem, since we use async calls. There might be an other request pending.
  • For different functions I now use different clients. And I cache them to reuse them.
  • Btw: maxIOThreadCount is not (no more?) an attribute of the Http Client Config. I use a counter now, and close the client after 5 calls and create a new one.

All the debugging is tricky :-( and takes a lot of time.
Any better idea for the implementation is still very welcome.

Thanks again and best regards
Birgit
Birgit Rieder
7r AG, Switzerland
SAN Developer
http://www.seven-r.ch
User avatar
rieder
 
Posts: 177
Joined: Thu Jan 26, 2012 5:18 pm

Re: Using HttpClient

Postby rieder » Thu Jun 01, 2023 6:57 pm

Hi

We now made a stress test, simulating teachers entering marks for their classes. We recalculate promotion values (http call) after each change of a mark. The current implementation is much more stable than before. But raises errors after about 25 calls. See the error below.

Can anyone tell from the error: Is this related to the client? Or has the server an error handling all the calls?

Thank you and kind regards
Birgit


ERROR com.servoy.j2db.util.Debug - Error executing a request to http://10.211.55.3:8183/servoy-service/ ... lePosition with method PUT with user: null, workstation: null, domain: null org.apache.http.impl.execchain.RequestAbortedException: Request execution failed
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:199) ~[?:?]
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186) ~[?:?]
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89) ~[?:?]
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110) ~[?:?]
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) ~[?:?]
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83) ~[?:?]
at com.servoy.extensions.plugins.http.BaseRequest.executeRequest(BaseRequest.java:239) ~[?:?]
at com.servoy.extensions.plugins.http.BaseRequest.access$000(BaseRequest.java:52) ~[?:?]
at com.servoy.extensions.plugins.http.BaseRequest$1.run(BaseRequest.java:392) ~[?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) ~[?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) ~[?:?]
at java.lang.Thread.run(Unknown Source) ~[?:?]
Caused by: java.util.concurrent.CancellationException: Operation aborted
at org.apache.http.pool.AbstractConnPool.operationAborted(AbstractConnPool.java:182) ~[?:?]
at org.apache.http.pool.AbstractConnPool.getPoolEntryBlocking(AbstractConnPool.java:397) ~[?:?]
at org.apache.http.pool.AbstractConnPool.access$300(AbstractConnPool.java:70) ~[?:?]
at org.apache.http.pool.AbstractConnPool$2.get(AbstractConnPool.java:253) ~[?:?]
at org.apache.http.pool.AbstractConnPool$2.get(AbstractConnPool.java:198) ~[?:?]
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.leaseConnection(PoolingHttpClientConnectionManager.java:306) ~[?:?]
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$1.get(PoolingHttpClientConnectionManager.java:282) ~[?:?]
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:190) ~[?:?]
Birgit Rieder
7r AG, Switzerland
SAN Developer
http://www.seven-r.ch
User avatar
rieder
 
Posts: 177
Joined: Thu Jan 26, 2012 5:18 pm


Return to Plugins and Beans

Who is online

Users browsing this forum: No registered users and 13 guests

cron