Skip to content

Don't try to parse non XML value in XPath matcher#1049

Merged
tomakehurst merged 5 commits into
wiremock:masterfrom
philippe-granet:master
Jan 13, 2019
Merged

Don't try to parse non XML value in XPath matcher#1049
tomakehurst merged 5 commits into
wiremock:masterfrom
philippe-granet:master

Conversation

@philippe-granet

Copy link
Copy Markdown
Contributor

We try to use Wiremock for performance tests, but there is a bottleneck.
We have a mix of XML and Json stubs, and Wiremock try to parse json request in XML (see issue #776 and #652).
Or parsing data in XML is a heavy operation (CPU intensive, generate exception, ...), so don't try to parse non XML value in XPath matcher

With this simple test case:

@Test
public void perfXmlTest() {
	perfRunXPath("matchingXPath on XML datas", "<perf-test>perf-data</perf-test>");
	perfRunXPath("matchingXPath on JSON datas", "{\"perf-test\": \"perf-data\"}");
}
private void perfRunXPath(String message, String value) {
	long ts = System.currentTimeMillis();
	for (int i = 0; i < 100000; i++) {
		WireMock.matchingXPath("//perf-test").match(value);
	}
	System.out.println(message + ":\t" + (System.currentTimeMillis() - ts) + "ms");
}

Without my merge request:
matchingXPath on XML datas: 19137ms
matchingXPath on JSON datas: 10376ms

With my merge request:
matchingXPath on XML datas: 19278ms
matchingXPath on JSON datas: 197ms

@philippe-granet philippe-granet changed the title For performance reason, don't try to parse non XML value in XPath matcher For performance reason, don't try to parse non XML value in XPath matcher and don't attempt Body pattern matching if URL not matching Dec 12, 2018
@philippe-granet philippe-granet changed the title For performance reason, don't try to parse non XML value in XPath matcher and don't attempt Body pattern matching if URL not matching Don't try to parse non XML value in XPath matcher and don't attempt Body pattern matching if URL not matching Dec 12, 2018
@tomakehurst

Copy link
Copy Markdown
Member

Again, thanks for this. I'm definitely keen to improve performance in this area, and clearly given your test results you've found a potentially significant optimisation.

I've added one comment against the code if you could take a quick look.

@philippe-granet

philippe-granet commented Jan 4, 2019

Copy link
Copy Markdown
Contributor Author

I've added one comment against the code if you could take a quick look.

@tomakehurst Sorry, which comment ?

@tomakehurst

Copy link
Copy Markdown
Member

Line 83 of RequestPattern (it's in this thread, for me at least).

@philippe-granet

Copy link
Copy Markdown
Contributor Author

@tomakehurst Sorry, I don't see it. Have you submit it?

Comment thread src/main/java/com/github/tomakehurst/wiremock/matching/RequestPattern.java Outdated
@tomakehurst

Copy link
Copy Markdown
Member

Doh! I didn't. Have now.

@philippe-granet philippe-granet changed the title Don't try to parse non XML value in XPath matcher and don't attempt Body pattern matching if URL not matching Don't try to parse non XML value in XPath matcher Jan 5, 2019
@tomakehurst tomakehurst merged commit 076244b into wiremock:master Jan 13, 2019
@tomakehurst

Copy link
Copy Markdown
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants