How to detect akka-http server request timeout? - akka-http

When writing an HTTP server using akka-http’s high-level Route API, is there a way to be notified that the request timeout has expired, or to check whether it is expired, or to check how much time remains? In implementing an expensive route, I would like to stop performing work on a request if the request times out.
Akka-http’s request timeout responds to HTTP requests with status code 503 Service Unavailable: “The server was not able to produce a timely response to your request.
Please try again in a short while!” It is configured using akka.http.server.request-timeout, which is 20 s by default.

Related

HTTP status 429 too many requests [duplicate]

I'm trying to hit the server with multiple requests for load testing. I have setup JMeter thread with 100 concurrent users per seconds. Each request read data from CSV (different tokens to identify users). But after few request I'm getting error:
429 Too Many Requests
How we can solve this? Any settings in Jmeter?
Or Do I need to change Apache settings?
As per HTTP Status 429 documentation
The HTTP 429 Too Many Requests response status code indicates the user has sent too many requests in a given amount of time ("rate limiting").
A Retry-After header might be included to this response indicating how long to wait before making a new request.
Most probably your JMeter test configuration is not correct, the reasons could be in:
You don't use HTTP Cookie Manager so all the requests fall under the same session and application reacts correspondingly
Your application limits rate of requests from a single IP. Consider going for IP Spoofing or Distributed Testing or both
You're using the same credentials for all virtual users, make sure that each JMeter virtual user has its own credentials and operates its own data. You can use i.e. CSV Data Set Config for parameterization.
This is most probably a DDOS protection in the application you’re testing so your options are to ask the infrastructure team or developers to disable it.
As per reference documentation:
The HTTP 429 Too Many Requests response status code indicates the user has sent too many requests in a given amount of time ("rate limiting").
A Retry-After header might be included to this response indicating how long to wait before making a new request.
There is nothing you can do ok jmeter side.

Writing tests with http request without response

I need to prepare a Java test (citrus framework) which initial step is sending a http request. Unfortunately my app under tests does not reply to this http request with anything while my testing framework expects to have a response and generates an error otherwise. The best way to deal with such a situation which came to my mind is to use some kind of a proxy between my testing framework and actual application which will forward the test request to the actual application and reply back to the testing framework with OK status not waiting for the response from app.
Does it make a sense? How could I prepare such a proxy assuming that my tests are to be running with maven invocation?
I see following options:
Fire and forget: send the Http request (using the fork mode on the send operation in Citrus) and do not care for the response at all. Just leave out the receive message action to ignore the response in Citrus.
Expect the timeout: Send the Http request and use the receive timeout action to verify that the client does not receive a response in the given time
Assert/catch the timeout exception: Use the assert or catch action in Citrus to handle the timeout exception when sending the http request
Personally I would go for the option #2 where you send the Http request and verify that there is no response for a given amount of time. This makes sure that the actual behavior of your application to not send any response does not change over time.

Is it possible for Apache to send a 'pause' or 'wait' response to client while running a PHP/Perl script?

When the Apache server receives a POST request, I want to immediately send back a response, stating that the client should wait and not send anything.
While at the same time client's request will be passed on to a script (either PHP or Perl). And then the script will send back a response to the client.
Is this possible? I know that it is possible for Apache to send a 4xx response header, so that the client would stop sending. But I want to run a script while the client has stopped sending and then have the client redirect to somewhere..
There are a few HTTP status codes that may be of use IF you want to be fully REST-ful and use the HTTP verbs (GET, POST, PUT, DELETE, etc) and status codes
https://www.restapitutorial.com/httpstatuscodes.html
In particular for what I am interpreting as your use case, status code 202 Accepted may be correct for your use:
The request has been accepted for processing, but the processing has
not been completed. The request might or might not eventually be acted
upon, as it might be disallowed when processing actually takes place.
There is no facility for re-sending a status code from an asynchronous
operation such as this.
The 202 response is intentionally non-committal. Its purpose is to
allow a server to accept a request for some other process (perhaps a
batch-oriented process that is only run once per day) without
requiring that the user agent's connection to the server persist until
the process is completed. The entity returned with this response
SHOULD include an indication of the request's current status and
either a pointer to a status monitor or some estimate of when the user
can expect the request to be fulfilled.

Solve 429 Too Many Requests issue while load testing using Jmeter

I'm trying to hit the server with multiple requests for load testing. I have setup JMeter thread with 100 concurrent users per seconds. Each request read data from CSV (different tokens to identify users). But after few request I'm getting error:
429 Too Many Requests
How we can solve this? Any settings in Jmeter?
Or Do I need to change Apache settings?
As per HTTP Status 429 documentation
The HTTP 429 Too Many Requests response status code indicates the user has sent too many requests in a given amount of time ("rate limiting").
A Retry-After header might be included to this response indicating how long to wait before making a new request.
Most probably your JMeter test configuration is not correct, the reasons could be in:
You don't use HTTP Cookie Manager so all the requests fall under the same session and application reacts correspondingly
Your application limits rate of requests from a single IP. Consider going for IP Spoofing or Distributed Testing or both
You're using the same credentials for all virtual users, make sure that each JMeter virtual user has its own credentials and operates its own data. You can use i.e. CSV Data Set Config for parameterization.
This is most probably a DDOS protection in the application you’re testing so your options are to ask the infrastructure team or developers to disable it.
As per reference documentation:
The HTTP 429 Too Many Requests response status code indicates the user has sent too many requests in a given amount of time ("rate limiting").
A Retry-After header might be included to this response indicating how long to wait before making a new request.
There is nothing you can do ok jmeter side.

Blocking Request

What does a server connection with a blocking request mean?
Thank You!
It means, when you make a request to the server, you wait until you hear back from it (blocking).
The advantage of this approach is that code that expects the request to complete will be ensured that the request has completed.
The downsides are that your code is "hung" until the request completes, and there is a chance that the request might not ever complete, which results in a hung thread and/or process.
Typically blocking requests are accompanied by timeouts, so after period of time, if no response is given, the call returns with an error indicated a timeout has elapsed, and you should diligently handle that case.
Web page requests are an example of a blocking request. When you type www.google.com into your browser, your browser makes a blocking request to Google's web server, waiting to display the response. If (for some crazy reason) google doesn't respond, you'll get a timeout error.