Appropriate HTTP code for an unavailable download? - http-status-codes

Which HTTP response code is appropriate for a download that is not available on the system but it will be available in the future.
If a browser/download manager asks for a file that is not available on the system at the moment (temporary unavailable), but we want the browser/DM to retry later for that file, which HTTP status code to return?

10.2.3 202 Accepted
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.
Source: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

HTTP 404 as defined here:
[...] The server has not found
anything matching the Request-URI. No
indication is given of whether the
condition is temporary or permanent.
[...]

Related

Sometimes I am getting 600 error in my Jmeter response

I have observed sometimes I am getting 600 error code in my jmeter response. I need help what was that and what things shall we implement to avoid this?
Thanks in advance.
HTTP Status Code 600 is not something defined by the standard, you need to consult your application developers and ask them what could be the cause of it.
I can think of the following possible reasons:
It happens due to missing or improperly implemented correlation
Your application gets overloaded and cannot handle the incoming requests properly, try increasing the load gradually and try to find the relationship between the number of users/request per second and presence of this error
You can add a Listener like Simple Data Writer to store request and response details, it might be the case you're sending a malformed request and application responds with 600 status code instead of normal 4xx
Make sure to follow JMeter Best Practices as it could also be the case JMeter fails to properly send the request due to bad configuration and/or lack of resources

Jmeter Results Confusion

I´m testing a software and its architecture with jmeter, I'm using a webservice that inserts some values to a table and in the middle of the load I shutdown the database server (I'm using a sql cluster architecutre) then, the backup server starts to recive the threads....
There´s a period of dead time between shutting down the main server and the start of the backup server... in that period of time, jmeter says the request was succesfully completed (maybe because the app server is active) but that´s not true beacuse there´s no any database server active that can process the request...
If I check the "view results as tree" response I have this:
<errorCode>751</errorCode>
<errorMessage>Cannot open database "DBNAME" requested by the login. The login failed.
Login failed for user 'USER'.</errorMessage>
Why is jmeter saying the response was ok when there isn't a database active?
How can I filter the results so jmeter only counts the results that are ok? or how can I say to jmeter that when the response has that error message it should count as an error?
JMeter considers HTTP Status Codes below 400 as successful, the fact your application returns HTTP Status code 200 (OK) or whatever below 400 indicates its incorrect behavior.
If you are totally sure that your application acting as designed you might want to configure JMeter to check response body to ensure that it doesn't contain <errorCode> and/or <errorMessage> tags via Response Assertion.
Check out Response Assertions in JMeter 3.2 - New and Improved article for more information on assertions concept, learn how to conditionally fail JMeter samplers and what exact configuration is needed to get this done

Getting high Error% in jmeter after run, how to know this error is due what (machine config issue, request issue..)

Getting high Error% in jmeter after run, how to know this error is due to out of memory or used machine doesn't have capability or the http request has an issue. In my case getting Error% in jmeter summary report is 97.50% (for login api) and when loaded this result in 'View results tree' can see 500 internal server errors or the failed requests. Please suggest what measures can be taken to analyse these errors.
As per the RFC 2616
10.5 Server Error 5xx
Response status codes beginning with the digit "5" indicate cases in which the server is aware that it has erred or is incapable of performing the request. Except when responding to a HEAD request, the server SHOULD include an entity containing an explanation of the error situation, and whether it is a temporary or permanent condition. User agents SHOULD display any included entity to the user. These response codes are applicable to any request method.
10.5.1 500 Internal Server Error
The server encountered an unexpected condition which prevented it from fulfilling the request.
So the possible reasons are in:
You are sending incorrect requests which cannot be processed on your server side. Check server logs for details, most probably you will be able to figure out something from them. If you don't have access to logs you can at least configure JMeter to save response data for failed requests, add the following lines to user.properties file to trigger this on:
jmeter.save.saveservice.output_format=xml
jmeter.save.saveservice.response_data.on_error=true
Check out Configuring JMeter chapter for more information.
It may be your application components configuration which is not suitable for high loads, i.e. your application server or database can be configured to accept not more than X connections and your load test is exceeding this value. The solution is again to check application, web server and database logs and make required configuration changes
It may be due to simple lack of resources, i.e. CPU or RAM on server side so you can monitor them using u.e. JMeter PerfMon Plugin. See How to Monitor Your Server Health & Performance During a JMeter Load Test for more details.

Can/Should a http read_timeout be retried?

I'm on a network that usually causes a ton of connection timeout issues, and ocasionally I'm running into read timeout issues as well. Retrying the code whenever a connect timeout happens fixes the problem with connecting to the server. Is is safe to retry the code whenever I get a read_timeout, or whould the response become corrupted? I'm using Ruby, with Net::HTTP client, but I guess this could apply to other languages as well.
A read_timeout means that the server did not send any data within the expected timeout. The response becoming corrupted is less likely as this is TCP.
To answer if it's safe or not to retry depends on what operation you're performing and/or any guarantees the service you're interacting with gives you.
In general GET should be safe to retry.
POST/PUT may need special handling (i.e. rereading some state before deciding to retry) as this usually means that something changes on the server.

async execution of tasks for a web application

A web application I am developing needs to perform tasks that are too long to be executed during the http request/response cycle. Typically, the user will perform the request, the server will take this request and, among other things, run some scripts to generate data (for example, render images with povray).
Of course, these tasks can take a long time, so the server should not hang for the scripts to complete execution before sending the response to the client. I therefore need to perform the execution of the scripts async, and give the client a "the resource is here, but not ready" and probably tell it a ajax endpoint to poll, so it can retrieve and display the resource when ready.
Now, my question is not relative to the design (although I would very much enjoy any hints on this regard as well). My question is: does a system to solve this issue already exists, so I do not reinvent the square wheel ? If I had to, I would use a process queue manager to submit the task and put a HTTP endpoint to shoot out the status, something like "pending", "aborted", "completed" to the ajax client, but if something similar already exists specifically for this task, I would mostly enjoy it.
I am working in python+django.
Edit: Please note that the main issue here is not how the server and the client must negotiate and exchange information about the status of the task.
The issue is how the server handles the submission and enqueue of very long tasks. In other words, I need a better system than having my server submit scripts on LSF. Not that it would not work, but I think it's a bit too much...
Edit 2: I added a bounty to see if I can get some other answer. I checked pyprocessing, but I cannot perform submission of a job and reconnect to the queue at a later stage.
You should avoid re-inventing the wheel here.
Check out gearman. It has libraries in a lot of languages (including python) and is fairly popular. Not sure if anyone has any out of the box ways to easily connect up django to gearman and ajax calls, but it shouldn't be do complicated to do that part yourself.
The basic idea is that you run the gearman job server (or multiple job servers), have your web request queue up a job (like 'resize_photo') with some arguments (like '{photo_id: 1234}'). You queue this as a background task. You get a handle back. Your ajax request is then going to poll on that handle value until it's marked as complete.
Then you have a worker (or probably many) that is a separate python process connect up to this job server and registers itself for 'resize_photo' jobs, does the work and then marks it as complete.
I also found this blog post that does a pretty good job summarizing it's usage.
You can try two approachs:
To call webserver every n interval and inform a job id; server processes and return some information about current execution of that task
To implement a long running page, sending data every n interval; for client, that HTTP request will "always" be "loading" and it needs to collect new information every time a new data piece is received.
About second option, you can to learn more by reading about Comet; Using ASP.NET, you can do something similiar by implementing System.Web.IHttpAsyncHandler interface.
I don't know of a system that does it, but it would be fairly easy to implement one's own system:
create a database table with jobid, jobparameters, jobresult
jobresult is a string that will hold a pickle of the result
jobparameters is a pickled list of input arguments
when the server starts working on a job, it creates a new row in the table, and spwans a new process to handle that, passing that process the jobid
the task handler process updates the jobresult in the table when it has finished
a webpage (xmlrpc or whatever you are using) contains a method 'getResult(jobid)' that will check the table for a jobresult
if it finds a result, it returns the result, and deletes the row from the table
otherwise it returns an empty list, or None, or your preferred return value to signal that the job is not finished yet
There are a few edge-cases to take care of so an existing framework would clearly be better as you say.
At first You need some separate "worker" service, which will be started separately at powerup and communicated with http-request handlers via some local IPC like UNIX-socket(fast) or database(simple).
During handling request cgi ask from worker state or other data and replay to client.
You can signal that a resource is being "worked on" by replying with a 202 HTTP code: the Client side will have to retry later to get the completed resource. Depending on the case, you might have to issue a "request id" in order to match a request with a response.
Alternatively, you could have a look at existing COMET libraries which might fill your needs more "out of the box". I am not sure if there are any that match your current Django design though.
Probably not a great answer for the python/django solution you are working with, but we use Microsoft Message Queue for things just like this. It basically runs like this
Website updates a database row somewhere with a "Processing" status
Website sends a message to the MSMQ (this is a non blocking call so it returns control back to the website right away)
Windows service (could be any program really) is "watching" the MSMQ and gets the message
Windows service updates the database row with a "Finished" status.
That's the gist of it anyways. It's been quite reliable for us and really straight forward to scale and manage.
-al
Another good option for python and django is Celery.
And if you think that Celery is too heavy for your needs then you might want to look at simple distributed taskqueue.

Resources