I am new to webapi calls. I have a bunch of webapi calls happening. I would like to check the performance of these calls using the locustio and swarm the users with the calls and record the time for each webapi call taken..
Below is the locustfile i have written.
from locust import HttpLocust, TaskSet, task
class MyTaskSet(TaskSet):
#task
def my_task(self):
print "executing my_task"
self.client.get('https://piprdweb.cds.com/piwebapi/streams/A0Ej3OLt_2RH0mvwiXA5DULmw-UVswK3W5hGvHhJaxRW7Owqi14iFv8x0KZLamRlaPPawUElQUkRBRlxQQ0dfUlNCT1BcUklHLjM0MlxCT1BTRU5UUllcU0lHTkFMU1xTVEFDSyBPTkVcWUVMTE9XIFBPRHxDQU4gMSBIVU1JRElUWSAtIFlFTExPVyBQT0Q/value?time=*-5s')
class MyLocust(HttpLocust):
task_set = MyTaskSet
min_wait = 5000
max_wait = 15000
Next when i am running the locust --host https://piprdweb.cds.com/piwebapi/ i am getting the below error
AttributeError
[2017-02-06 15:14:26,378] srvgdyplmvrc01.nov.com/ERROR/stderr: :
[2017-02-06 15:14:26,378] srvgdyplmvrc01.nov.com/ERROR/stderr: 'module' object has no attribute 'NSIG'
Please correct me if i am making a mistake .
Related
I have a scenario where i want to do a get call after running the post-call for give amount of time and the Get call is only for once after running the POST calls, any suggestions on how to do in Gatling
You could do something like this:
def basicScn: ScenarioBuilder = scenario("BasicScenario")
.exec(postReq)
.pause(5)
.exec(getReq)
val postReq: HttpRequestBuilder = http("PostRequest")
.post("/hello/world")
.body(StringBody("${body}")).asJson
val getReq: HttpRequestBuilder = http("GetRequest")
.get("/stack/over/flow")
I'm executing JMeter task for a few hours on a server,
I want to be able to pause execution for a few seconds/minutes and resume when server finish restarted
Is there a way to signal JMeter to pause and resume its execution?
I saw similar question, but it doesn't fit my issue
As of current JMeter version 5.3 there is no way to accomplish your "issue" with built-in JMeter components.
The easiest solution I can think if is: given you're restarting your server it should be not available for some time and when it becomes available - it should respond with a HTML page containing some text.
So you can "wait" for the server to be up and running as follows:
Add JSR223 Sampler to the appropriate place in the Test Plan where you need to "wait' for the server to be up and running
Put the following code into "Script" area:
import org.apache.http.client.config.RequestConfig
import org.apache.http.client.methods.HttpGet
import org.apache.http.impl.client.HttpClientBuilder
import org.apache.http.util.EntityUtils
SampleResult.setIgnore()
def retry = true
def requestConfig = RequestConfig.custom().setConnectTimeout(1000).setSocketTimeout(1000).build()
def httpClient = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build()
while (retry) {
def httpGet = new HttpGet('http://jmeter.apache.org')
try {
def entity = httpClient.execute(httpGet).getEntity()
if (EntityUtils.toString(entity).contains('Apache JMeter')) {
log.info('Application is up, proceeding')
retry = false
} else {
log.info('Application is still down, waiting for 5 seconds before retry')
sleep(5000)
}
}
catch (Throwable ex) {
sleep(5000)
ex.printStackTrace()
}
}
That's it, the code will try to open the web page and look for some text in it, if the page doesn't open and/or text is not present - it will wait for 5 seconds and retry
More information:
HttpClient Quick Start
Apache Groovy - Why and How You Should Use It
I want my lambda function to return the response of another lambda function invoked via AWS API Gateway.
Both functions are deployed by Lambda Chalice to different APIs.
When the first function sends a request to the 2nd functions API endpoint, I am getting an error response saying that "The request could not be satisfied".
Any help is appreciated.
Edit to include some code as requested; shortened for brevity:
#app.route('/verify_user_token', methods=['GET'], cors=True)
def verify_user_token():
request = app.current_request
params = request.query_params or {}
# do your things here; if all goes well:
r = requests.get(ANOTHER_AWS_API_GATEWAY_ENDPOINT_URL, data=params)
return r.text
I'm getting started with Google App Engine. I want to make an AJAX chat.
class ChatMessage(db.Model):
message = db.StringProperty()
created = db.DateTimeProperty(auto_now_add=True)
class RPCHandler(webapp.RequestHandler):
##get message every 4 seconds
def get(self):
que = db.Query(ChatMessage).order('-created')
chat_list = que.fetch(limit=3)
jencoded_chat_list = gaejsonEncoder.encode(chat_list) ##my own module
self.response.out.write(jencoded_chat_list)
RESULT: message3,message2,message1
This is what I intended.
I wanted to add POST ajax Request, so added RPCHandler2.
class RPCHandler2(webapp.RequestHandler):
def post(self):
msg = self.request.get('message')
if msg == '':
return
newchat = ChatMessage(message=msg)
newchat.put()
que = db.Query(ChatMessage).order('-created')
chat_list = que.fetch(limit=3))
jencoded_chat_list = gaejsonEncoder.encode(chat_list)
self.response.out.write(jencoded_chat_list)
I write "POST Message!" in textarea and click the button,
RESULT: POST Message!,message3,message2
This is what I wanted.
But 4 seconds later, 'GET' started and
RESULT: message3,message2,message1
Why 'GET' couldn't get the new message from datastore?
Thanks in advance.
If you are using the high replication datastore you might be facing an "eventual consistency" problem. The datastore replica handling the get request may not have received the recently submitted data yet.
If you put the newchat.put() inside of a transaction it's more likely that future gets will be consistent.
I have the following Business Process defined within a Production on an Intersystems Cache Installation
/// Makes a call to Merlin based on the message sent to it from the pre-processor
Class sgh.Process.MerlinProcessor Extends Ens.BusinessProcess [ ClassType = persistent, ProcedureBlock ]
{
Property WorkingDirectory As %String;
Property WebServer As %String;
Property CacheServer As %String;
Property Port As %String;
Property Location As %String;
Parameter SETTINGS = "WorkingDirectory,WebServer,Location,Port,CacheServer";
Method OnRequest(pRequest As sgh.Message.MerlinTransmissionRequest, Output pResponse As Ens.Response) As %Status
{
Set tSC=$$$OK
Do ##class(sgh.Utils.Debug).LogDebugMsg("Packaging an HTTP request for Saved form "_pRequest.DateTimeSaved)
Set dateTimeSaved = pRequest.DateTimeSaved
Set patientId = pRequest.PatientId
Set latestDateTimeSaved = pRequest.LatestDateTimeSaved
Set formName = pRequest.FormName
Set formId = pRequest.FormId
Set episodeNumber = pRequest.EpisodeNumber
Set sentElectronically = pRequest.SentElectronically
Set styleSheet = pRequest.PrintName
Do ##class(sgh.Utils.Debug).LogDebugMsg("Creating HTTP Request Class")
set HTTPReq = ##class(%Net.HttpRequest).%New()
Set HTTPReq.Server = ..WebServer
Set HTTPReq.Port = ..Port
do HTTPReq.InsertParam("DateTimeSaved",dateTimeSaved)
do HTTPReq.InsertParam("HospitalNumber",patientId)
do HTTPReq.InsertParam("Episode",episodeNumber)
do HTTPReq.InsertParam("Stylesheet",styleSheet)
do HTTPReq.InsertParam("Server",..CacheServer)
Set Status = HTTPReq.Post(..Location,0) Quit:$$$ISERR(tSC)
Do ##class(sgh.Utils.Debug).LogDebugMsg("Sent the following request: "_Status)
Quit tSC
}
}
The thing is when I check the debug value (which is defined as a global) all I get is the number '1' - I have no idea therefore if the request has succeeded or even what is wrong (if it has not)
What do I need to do to find out
A) What is the actual web call being made?
B) What the response is?
There is a really slick way to get the answer the two questions you've asked, regardless of where you're using the code. Check the documentation out on the %Net.HttpRequest object here: http://docs.intersystems.com/ens20102/csp/docbook/DocBook.UI.Page.cls?KEY=GNET_http and the class reference here: http://docs.intersystems.com/ens20102/csp/documatic/%25CSP.Documatic.cls?APP=1&LIBRARY=ENSLIB&CLASSNAME=%25Net.HttpRequest
The class reference for the Post method has a parameter called test, that will do what you're looking for. Here's the excerpt:
method Post(location As %String = "", test As %Integer = 0, reset As %Boolean = 1) as %Status
Issue the Http 'post' request, this is used to send data to the web server such as the results of a form, or upload a file. If this completes correctly the response to this request will be in the HttpResponse. The location is the url to request, e.g. '/test.html'. This can contain parameters which are assumed to be already URL escaped, e.g. '/test.html?PARAM=%25VALUE' sets PARAM to %VALUE. If test is 1 then instead of connecting to a remote machine it will just output what it would have send to the web server to the current device, if test is 2 then it will output the response to the current device after the Post. This can be used to check that it will send what you are expecting. This calls Reset automatically after reading the response, except in test=1 mode or if reset=0.
I recommend moving this code to a test routine to view the output properly in terminal. It would look something like this:
// To view the REQUEST you are sending
Set sc = request.Post("/someserver/servlet/webmethod",1)
// To view the RESPONSE you are receiving
Set sc = request.Post("/someserver/servlet/webmethod",2)
// You could also do something like this to parse your RESPONSE stream
Write request.HttpResponse.Data.Read()
I believe the answer you want to A) is in the Server and Location properties of your %Net.HttpRequest object (e.g., HTTPReq.Server and HTTPReq.Location).
For B), the response information should be in the %Net.HttpResponse object stored in the HttpResponse property (e.g. HTTPReq.HttpResponse) after your call is completed.
I hope this helps!
-Derek
(edited for formatting)
From that code sample it looks like you're using Ensemble, not straight-up Cache.
In that case you should be doing this HTTP call in a Business Operation that uses the HTTP Outbound Adapter, not in your Business Process.
See this link for more info on HTTP Adapters:
http://docs.intersystems.com/ens20102/csp/docbook/DocBook.UI.Page.cls?KEY=EHTP
You should also look into how to use the Ensemble Message Browser. That should help with your logging needs.