我有一个仅由模拟操作组成的Azure API Management API。大多数,如附加图像的底部,以十分之一毫秒运行。然而,一个test / plain进入并返回application / json通常会在几十秒内运行(图像顶部)。我发现这是使用开发者控制台或从Logic Apps调用。我的案子有1.7K进入,返回的JSON大到26K。
仍有大量的响应时间似乎过多。可能有解释吗?
模拟
返回的My Representation示例{
"FunctionalGroup": {
"TransactionSet": {
"@controlNumber": "270001",
"Area": [
{
"Segment": [
{
"@id": "BEG",
"Element": [
{
"@pos": "1",
"#text": "00"
},
{
"@pos": "2",
"#text": "SA"
},
{
"@pos": "3",
"#text": "86816853"
},
{
"@pos": "5",
"@date": "2015-04-09",
"#text": "20150409"
}
]
},
{
"@id": "REF",
"Element": [
{
"@pos": "1",
"#text": "DP"
},
{
"@pos": "2",
"#text": "16"
},
{
"@pos": "3",
"#text": "DEPARTMENTA"
}
]
}
],
"SegmentLoop": [
{
"@id": "N9",
"@name": "N9",
"Segment": [
{
"@id": "N9",
"Element": [
{
"@pos": "1",
"#text": "ST"
},
{
"@pos": "2",
"#text": "001"
}
]
},
{
"@id": "DTM",
"Element": [
{
"@pos": "1",
"#text": "010"
},
{
"@pos": "2",
"@date": "2015-04-12",
"#text": "20150412"
},
{
"@pos": "3",
"@time": "00:00:00",
"#text": "0000"
}
]
},
{
"@id": "DTM",
"Element": [
{
"@pos": "1",
"#text": "002"
},
{
"@pos": "2",
"@date": "2015-04-12",
"#text": "20150412"
},
{
"@pos": "3",
"@time": "12:34:34",
"#text": "123456"
}
]
},
{
"@id": "DTM",
"Element": [
{
"@pos": "1",
"#text": "001"
},
{
"@pos": "2",
"@date": "2015-04-30",
"#text": "20150430"
},
{
"@pos": "3",
"@time": "12:34:34.789",
"#text": "123456789"
}
]
}
]
},
{
"@id": "N1",
"@name": "N1",
"Segment": [
{
"@id": "N1",
"Element": [
{
"@pos": "1",
"#text": "ST"
},
{
"@pos": "2",
"#text": "COMPANY INC."
},
{
"@pos": "3",
"#text": "92"
},
{
"@pos": "4",
"#text": "001"
}
]
},
{
"@id": "N3",
"Element": [
{
"@pos": "1",
"#text": "123 main street"
},
{
"@pos": "2",
"#text": "PH:(644)123-4567"
}
]
},
{
"@id": "N4",
"Element": [
{
"@pos": "1",
"#text": "Elk Grove Village"
},
{
"@pos": "2",
"#text": "IL"
},
{
"@pos": "3",
"#text": "6007"
},
{
"@pos": "4",
"#text": "US"
}
]
}
]
},
{
"@id": "N1",
"@name": "N1",
"Segment": [
{
"@id": "N1",
"Element": [
{
"@pos": "1",
"#text": "SF"
},
{
"@pos": "2",
"#text": "EDGE ENTERPRISES"
},
{
"@pos": "3",
"#text": "92"
},
{
"@pos": "4",
"#text": "99999"
}
]
},
{
"@id": "N3",
"Element": [
{
"@pos": "1",
"#text": "2645 W. Coast Highway"
}
]
},
{
"@id": "N4",
"Element": [
{
"@pos": "1",
"#text": "Silicon Valley"
},
{
"@pos": "2",
"#text": "CA"
},
{
"@pos": "3",
"#text": "56874"
},
{
"@pos": "4",
"#text": "US"
}
]
}
]
}
]
},
{
"SegmentLoop": [
{
"@id": "PO1",
"@name": "PO1",
"Segment": [
{
"@id": "PO1",
"Element": [
{
"@pos": "1",
"#text": "1"
},
{
"@pos": "2",
"#text": "96"
},
{
"@pos": "3",
"#text": "EA"
},
{
"@pos": "4",
"#text": "2.05"
},
{
"@pos": "6",
"#text": "BP"
},
{
"@pos": "7",
"#text": "HB-Natural Adult Bat"
}
]
}
],
"SegmentLoop": [
{
"@id": "PID",
"@name": "PID",
"Segment": [
{
"@id": "PID",
"Element": [
{
"@pos": "1",
"#text": "F"
},
{
"@pos": "5",
"#text": "DESCRIPTION"
}
]
}
]
}
]
}
]
},
{
"SegmentLoop": [
{
"@id": "CTT",
"@name": "CTT",
"Segment": [
{
"@id": "CTT",
"Element": [
{
"@pos": "1",
"#text": "6"
}
]
},
{
"@id": "AMT",
"Element": [
{
"@pos": "1",
"#text": "TT"
},
{
"@pos": "2",
"@number": "1000.00",
"#text": "100000"
}
]
}
]
}
]
}
]
}
}
}
我的相关API操作政策
<policies>
<inbound>
<!--base: Begin Global scope-->
<!-- PC-1404 -->
<set-query-parameter name="subscription-key" exists-action="delete" />
<!--base: End Global scope-->
</inbound>
<backend>
<!--base: Begin Global scope-->
<forward-request />
<!--base: End Global scope-->
</backend>
<outbound>
<mock-response status-code="200" content-type="application/json" />
</outbound>
<on-error>
<!--base: Begin Global scope-->
<!-- By placing policy statements in the on-error section you can review the error by
using the context.LastError property, inspect and customize the error response using the
set-body policy, and configure what happens if an error occurs.
There are error codes for built-in steps and for errors that may occur during the processing of
policy statements.
For more information, see https://msdn.microsoft.com/en-us/library/azure/mt629506.aspx
statements to be applied if there is an error condition go here -->
<!-- for CORS support to Office Add-In to detect subscription key errors, etc. PLEX-JIRA: PC-725 TSCH 8/16/16 -->
<set-header name="Access-Control-Allow-Origin" exists-action="override">
<value>*</value>
</set-header>
<!--base: End Global scope-->
</on-error>
答案 0 :(得分:2)
我发现我需要将模拟调用移动到入站部分。这是从前到后(我实际上没有一个后端被认为是花时间)。新的op政策是
RSpec.describe "API V1 Bathrooms", type: 'request' do
describe "POST /api/v1/bathrooms" do
context "with valid parameters" do
let(:valid_params) do
{
bathroom: {
establishment: "Fake Place",
address: "123 Main St",
city: "Cityton",
state: "NY",
zip: "11111",
gender: "Unisex",
key_needed: false,
toilet_quantity: 1
}
}
end
it "creates a new bathroom" do
user = FactoryGirl.create(:user, email: "email1@website.com")
login_as(user, :scope => :user)
expect { post "/api/v1/bathrooms", params: valid_params }.to change(Bathroom, :count).by(+1)
expect(response).to have_http_status :created
expect(response.headers['Location']).to eq api_v1_bathroom_url(Bathroom.last)
end
it "creates a bathroom with the correct attributes" do
user = FactoryGirl.create(:user, email: "email2@website.com")
login_as(user, :scope => :user)
post "/api/v1/bathrooms", params: valid_params
expect(Bathroom.last).to have_attributes valid_params[:bathroom]
end
end
end
end