Skip to content

Commit 719c3f8

Browse files
authored
[Text Analytics] Adding performance testing for language detection (Azure#14020)
Adds performance testing for text analytics by testing `detectLanguage`. The test is parameterized over the number of documents to send (1-1000). Fixes Azure#13591.
1 parent d1d33a4 commit 719c3f8

File tree

9 files changed

+181
-5
lines changed

9 files changed

+181
-5
lines changed

common/config/rush/pnpm-lock.yaml

Lines changed: 24 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

eng/.docsettings.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ omitted_paths:
22
- documentation/ServicePrincipal/*
33
- eng/*
44
- sdk/*/arm-*
5+
- sdk/*/perf-tests/*
56
- sdk/core/README.md
67
- sdk/cognitiveservices/*
78
- sdk/communication/*/test/README.md
@@ -25,7 +26,6 @@ omitted_paths:
2526
- sdk/schemaregistry/README.md
2627
- sdk/storage/*/test/README.md
2728
- sdk/storage/storage-internal-avro/*
28-
- sdk/storage/perf-tests/*/README.md
2929
- sdk/storage/*/test/perfstress/track-1/*
3030
- sdk/storage/*/test/perfstress/track-2/*
3131
- sdk/textanalytics/*/test/README.md

rush.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,11 @@
642642
"projectFolder": "sdk/digitaltwins/digital-twins-core",
643643
"versionPolicyName": "client"
644644
},
645+
{
646+
"packageName": "@azure-tests/perf-ai-text-analytics",
647+
"projectFolder": "sdk/textanalytics/perf-tests/text-analytics",
648+
"versionPolicyName": "test"
649+
},
645650
{
646651
"packageName": "@azure-tests/perf-storage-blob",
647652
"projectFolder": "sdk/storage/perf-tests/storage-blob",
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Performance Testing for Text Analytics
2+
3+
## Instructions
4+
5+
1. Build the ai-text-analytics perf tests package `rush build -t perf-ai-text-analytics`.
6+
2. Copy the `sample.env` file and name it as `.env`.
7+
3. Create a cognitive services account and populate the `.env` file with the relevant credentials.
8+
4. Refer to the [rate limits](https://docs.microsoft.com/azure/cognitive-services/text-analytics/concepts/data-limits?tabs=version-3) and then run the tests as follows
9+
10+
- detect language
11+
- `npm run perf-test:node -- DetectLanguageTest --warmup 1 --iterations 1 --parallel 50 --duration 15 -n 1000`
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "@azure-tests/perf-ai-text-analytics",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "",
6+
"keywords": [],
7+
"author": "",
8+
"license": "ISC",
9+
"dependencies": {
10+
"@azure/ai-text-analytics": "^5.1.0-beta.4",
11+
"@azure/identity": "^1.1.0",
12+
"@azure/test-utils-perfstress": "^1.0.0",
13+
"dotenv": "^8.2.0"
14+
},
15+
"devDependencies": {
16+
"@types/dotenv": "8.2.0",
17+
"@types/node": "^8.0.0",
18+
"tslib": "^2.0.0",
19+
"ts-node": "^8.3.0",
20+
"typescript": "4.1.2"
21+
},
22+
"private": true,
23+
"scripts": {
24+
"perf-test:node": "ts-node test/index.spec.ts",
25+
"audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit",
26+
"build": "tsc -p .",
27+
"build:samples": "echo skipped",
28+
"build:test": "echo skipped",
29+
"check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
30+
"clean": "rimraf dist dist-esm test-dist typings *.tgz *.log",
31+
"format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
32+
"integration-test:browser": "echo skipped",
33+
"integration-test:node": "echo skipped",
34+
"integration-test": "echo skipped",
35+
"lint:fix": "eslint package.json src test --ext .ts --fix --fix-type [problem,suggestion]",
36+
"lint": "eslint package.json src test --ext .ts -f html -o storage-blob-perf-test-lintReport.html || exit 0",
37+
"pack": "npm pack 2>&1",
38+
"prebuild": "npm run clean",
39+
"unit-test:browser": "echo skipped",
40+
"unit-test:node": "echo skipped",
41+
"unit-test": "echo skipped",
42+
"test:browser": "echo skipped",
43+
"test:node": "echo skipped",
44+
"test": "echo skipped"
45+
}
46+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Used in most samples. Retrieve these values from a Cognitive Services instance
2+
# in the Azure Portal.
3+
ENDPOINT="https://<resource name>.cognitiveservies.azure.com/"
4+
TEXT_ANALYTICS_API_KEY="<text analytics api key>"
5+
6+
# Used to authenticate using Azure AD as a service principal for role-based authentication
7+
# in the tokenAuth sample.
8+
#
9+
# See the documentation for `EnvironmentCredential` at the following link:
10+
# https://docs.microsoft.com/javascript/api/@azure/identity/environmentcredential
11+
AZURE_TENANT_ID=<AD tenant id or name>
12+
AZURE_CLIENT_ID=<ID of the user/service principal to authenticate as>
13+
AZURE_CLIENT_SECRET=<client secret used to authenticate to Azure AD>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
import {
5+
PerfStressTest,
6+
PerfStressOptionDictionary,
7+
getEnvVar
8+
} from "@azure/test-utils-perfstress";
9+
import {
10+
AzureKeyCredential,
11+
TextAnalyticsClient,
12+
DetectLanguageOptions
13+
} from "@azure/ai-text-analytics";
14+
import { TokenCredential, DefaultAzureCredential } from "@azure/identity";
15+
16+
interface DetectLanguagePerfTestOptions extends DetectLanguageOptions {
17+
"documents-count": number;
18+
}
19+
20+
export class DetectLanguageTest extends PerfStressTest<DetectLanguagePerfTestOptions> {
21+
options: PerfStressOptionDictionary<DetectLanguagePerfTestOptions> = {
22+
"documents-count": {
23+
required: true,
24+
description: "Number of documents",
25+
shortName: "n",
26+
longName: "docs-count",
27+
defaultValue: 10
28+
}
29+
};
30+
client: TextAnalyticsClient;
31+
docs: string[] = [];
32+
33+
constructor() {
34+
super();
35+
this.options = this.parsedOptions;
36+
this.docs = Array(this.parsedOptions["documents-count"]?.value!).fill(
37+
"Detta är ett dokument skrivet på engelska."
38+
);
39+
let credential: TokenCredential | AzureKeyCredential;
40+
41+
try {
42+
credential = new DefaultAzureCredential();
43+
} catch (e) {
44+
credential = new AzureKeyCredential(process.env.TEXT_ANALYTICS_API_KEY ?? "");
45+
}
46+
47+
const endpoint = getEnvVar("ENDPOINT");
48+
49+
this.client = new TextAnalyticsClient(endpoint, credential);
50+
}
51+
52+
async runAsync(): Promise<void> {
53+
await this.client.detectLanguage(this.docs, "en");
54+
}
55+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
import { PerfStressProgram, selectPerfStressTest } from "@azure/test-utils-perfstress";
5+
import { DetectLanguageTest } from "./detectLanguage.spec";
6+
7+
import dotenv from "dotenv";
8+
dotenv.config();
9+
10+
console.log("=== Starting the perfStress test ===");
11+
12+
const perfStressProgram = new PerfStressProgram(selectPerfStressTest([DetectLanguageTest]));
13+
14+
perfStressProgram.run();
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "../../../../tsconfig.package",
3+
"compilerOptions": {
4+
"target": "ES2015",
5+
"declarationDir": "./typings/latest",
6+
"lib": ["ES6", "ESNext.AsyncIterable", "DOM"],
7+
"noEmit": true
8+
},
9+
"compileOnSave": true,
10+
"exclude": ["node_modules"],
11+
"include": ["./test/**/*.ts"]
12+
}

0 commit comments

Comments
 (0)