[Text Analytics] Adding performance testing for language detection (#14020)
Adds performance testing for text analytics by testing `detectLanguage`. The test is parameterized over the number of documents to send (1-1000). Fixes https://github.com/Azure/azure-sdk-for-js/issues/13591.
This commit is contained in:
Родитель
d1d33a4367
Коммит
719c3f82a8
|
@ -43,6 +43,7 @@ dependencies:
|
|||
'@rush-temp/mixedreality-authentication': file:projects/mixedreality-authentication.tgz
|
||||
'@rush-temp/mock-hub': file:projects/mock-hub.tgz
|
||||
'@rush-temp/monitor-opentelemetry-exporter': file:projects/monitor-opentelemetry-exporter.tgz
|
||||
'@rush-temp/perf-ai-text-analytics': file:projects/perf-ai-text-analytics.tgz
|
||||
'@rush-temp/perf-storage-blob': file:projects/perf-storage-blob.tgz
|
||||
'@rush-temp/quantum-jobs': file:projects/quantum-jobs.tgz
|
||||
'@rush-temp/schema-registry': file:projects/schema-registry.tgz
|
||||
|
@ -8809,6 +8810,7 @@ packages:
|
|||
'@types/node': 8.10.66
|
||||
assert: 1.5.0
|
||||
chai: 4.3.0
|
||||
cross-env: 7.0.3
|
||||
eslint: 7.20.0
|
||||
events: 3.2.0
|
||||
karma: 5.2.3
|
||||
|
@ -8841,7 +8843,7 @@ packages:
|
|||
dev: false
|
||||
name: '@rush-temp/core-lro'
|
||||
resolution:
|
||||
integrity: sha512-rmOOOAVy2ARW+f9uBSRHrvOoY6KIE3LsfLLDDWZUhZdGOuhbdQVjMmOt0Wy/HTRo+Zxh/c5WAYAbTXqZfARP1Q==
|
||||
integrity: sha512-PKEMNt6k7V6j5faOpNM+jFMnz9GKF5sCsJmwXkJ7ERdHIJFcKtgd0RuQKA+JTY+i01u3UnQhzxITfELU3wRZfA==
|
||||
tarball: file:projects/core-lro.tgz
|
||||
version: 0.0.0
|
||||
file:projects/core-paging.tgz:
|
||||
|
@ -8938,7 +8940,7 @@ packages:
|
|||
dev: false
|
||||
name: '@rush-temp/core-util'
|
||||
resolution:
|
||||
integrity: sha512-4OU5OFYftkpFRv1aRCZaYrY34EfykkCVgzXXO2NW4EyU9QXtgM2cZvEEzP/elvBXUxCJfG/qtByBeEqjL2pqwA==
|
||||
integrity: sha512-OImydy+qxO0N84cf43gplu2RmV/TAlWN/BXt/sDRdAfNPVnKz91LODK4lZdwQW7ounVRp4FN8MdsfgCyiEnajQ==
|
||||
tarball: file:projects/core-util.tgz
|
||||
version: 0.0.0
|
||||
file:projects/core-xml.tgz:
|
||||
|
@ -9910,6 +9912,21 @@ packages:
|
|||
integrity: sha512-Wfak3T6DRQr5CH2DFIOOpsHf1jWps/pkwoLUC185vsw5dO5F1BSnYBRfhBzAWWNr1ot1R60Puy+whBcK0lq8Rw==
|
||||
tarball: file:projects/monitor-opentelemetry-exporter.tgz
|
||||
version: 0.0.0
|
||||
file:projects/perf-ai-text-analytics.tgz:
|
||||
dependencies:
|
||||
'@azure/identity': 1.2.3
|
||||
'@types/dotenv': 8.2.0
|
||||
'@types/node': 8.10.66
|
||||
dotenv: 8.2.0
|
||||
ts-node: 8.10.2_typescript@4.1.2
|
||||
tslib: 2.1.0
|
||||
typescript: 4.1.2
|
||||
dev: false
|
||||
name: '@rush-temp/perf-ai-text-analytics'
|
||||
resolution:
|
||||
integrity: sha512-F+eeV+aopIGTZp8/7sq8QGdNFqVQw5qGaZFEHi6paj/NDAk/2xb0lUMupAgkxHrH243PdvM2+Xr6s0CC3p4XFw==
|
||||
tarball: file:projects/perf-ai-text-analytics.tgz
|
||||
version: 0.0.0
|
||||
file:projects/perf-storage-blob.tgz:
|
||||
dependencies:
|
||||
'@types/dotenv': 8.2.0
|
||||
|
@ -9918,13 +9935,14 @@ packages:
|
|||
'@types/uuid': 8.3.0
|
||||
dotenv: 8.2.0
|
||||
node-fetch: 2.6.1
|
||||
ts-node: 8.10.2_typescript@4.1.2
|
||||
tslib: 2.1.0
|
||||
typescript: 4.1.2
|
||||
uuid: 8.3.2
|
||||
dev: false
|
||||
name: '@rush-temp/perf-storage-blob'
|
||||
resolution:
|
||||
integrity: sha512-ZZQ4YkQ+XG58fZ+la3Gm6pgCkZJkFMfjacNkgkWJs7USxGAfh4atkSDCXL+rDyhc9W1OALwC4tuVRkaXCSmyUg==
|
||||
integrity: sha512-U5zCPyEZxncGaINCHSpdYEoDttTYSNTKVCqzCqP1TRavjM3RBY2ulM99YHTIQcj4l0m8IpH0ousaugFVgd68XA==
|
||||
tarball: file:projects/perf-storage-blob.tgz
|
||||
version: 0.0.0
|
||||
file:projects/quantum-jobs.tgz:
|
||||
|
@ -10680,6 +10698,7 @@ packages:
|
|||
chai-as-promised: 7.1.1_chai@4.3.0
|
||||
cross-env: 7.0.3
|
||||
dotenv: 8.2.0
|
||||
downlevel-dts: 0.4.0
|
||||
eslint: 7.20.0
|
||||
inherits: 2.0.4
|
||||
karma: 5.2.3
|
||||
|
@ -10707,7 +10726,7 @@ packages:
|
|||
dev: false
|
||||
name: '@rush-temp/template'
|
||||
resolution:
|
||||
integrity: sha512-pEmmjxvEE493reTCIY95srFHxG/f3nqzcjIwjtoP/nq19qB8RuFpqHf5uIFsShMl/t/jNNpeyeX1w+3Diy+dcg==
|
||||
integrity: sha512-vDIEM+G9J4AdjHkdyKddr9xE5QmzY0aDsqB6EIU51xKfUk4dsmSnpwKbmj2wiESNqHIQUCEfQaAp5sYKUyKneQ==
|
||||
tarball: file:projects/template.tgz
|
||||
version: 0.0.0
|
||||
file:projects/test-utils-multi-version.tgz:
|
||||
|
@ -10883,6 +10902,7 @@ specifiers:
|
|||
'@rush-temp/mixedreality-authentication': file:./projects/mixedreality-authentication.tgz
|
||||
'@rush-temp/mock-hub': file:./projects/mock-hub.tgz
|
||||
'@rush-temp/monitor-opentelemetry-exporter': file:./projects/monitor-opentelemetry-exporter.tgz
|
||||
'@rush-temp/perf-ai-text-analytics': file:./projects/perf-ai-text-analytics.tgz
|
||||
'@rush-temp/perf-storage-blob': file:./projects/perf-storage-blob.tgz
|
||||
'@rush-temp/quantum-jobs': file:./projects/quantum-jobs.tgz
|
||||
'@rush-temp/schema-registry': file:./projects/schema-registry.tgz
|
||||
|
|
|
@ -2,6 +2,7 @@ omitted_paths:
|
|||
- documentation/ServicePrincipal/*
|
||||
- eng/*
|
||||
- sdk/*/arm-*
|
||||
- sdk/*/perf-tests/*
|
||||
- sdk/core/README.md
|
||||
- sdk/cognitiveservices/*
|
||||
- sdk/communication/*/test/README.md
|
||||
|
@ -25,7 +26,6 @@ omitted_paths:
|
|||
- sdk/schemaregistry/README.md
|
||||
- sdk/storage/*/test/README.md
|
||||
- sdk/storage/storage-internal-avro/*
|
||||
- sdk/storage/perf-tests/*/README.md
|
||||
- sdk/storage/*/test/perfstress/track-1/*
|
||||
- sdk/storage/*/test/perfstress/track-2/*
|
||||
- sdk/textanalytics/*/test/README.md
|
||||
|
|
|
@ -642,6 +642,11 @@
|
|||
"projectFolder": "sdk/digitaltwins/digital-twins-core",
|
||||
"versionPolicyName": "client"
|
||||
},
|
||||
{
|
||||
"packageName": "@azure-tests/perf-ai-text-analytics",
|
||||
"projectFolder": "sdk/textanalytics/perf-tests/text-analytics",
|
||||
"versionPolicyName": "test"
|
||||
},
|
||||
{
|
||||
"packageName": "@azure-tests/perf-storage-blob",
|
||||
"projectFolder": "sdk/storage/perf-tests/storage-blob",
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
# Performance Testing for Text Analytics
|
||||
|
||||
## Instructions
|
||||
|
||||
1. Build the ai-text-analytics perf tests package `rush build -t perf-ai-text-analytics`.
|
||||
2. Copy the `sample.env` file and name it as `.env`.
|
||||
3. Create a cognitive services account and populate the `.env` file with the relevant credentials.
|
||||
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
|
||||
|
||||
- detect language
|
||||
- `npm run perf-test:node -- DetectLanguageTest --warmup 1 --iterations 1 --parallel 50 --duration 15 -n 1000`
|
|
@ -0,0 +1,46 @@
|
|||
{
|
||||
"name": "@azure-tests/perf-ai-text-analytics",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "",
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@azure/ai-text-analytics": "^5.1.0-beta.4",
|
||||
"@azure/identity": "^1.1.0",
|
||||
"@azure/test-utils-perfstress": "^1.0.0",
|
||||
"dotenv": "^8.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/dotenv": "8.2.0",
|
||||
"@types/node": "^8.0.0",
|
||||
"tslib": "^2.0.0",
|
||||
"ts-node": "^8.3.0",
|
||||
"typescript": "4.1.2"
|
||||
},
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"perf-test:node": "ts-node test/index.spec.ts",
|
||||
"audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit",
|
||||
"build": "tsc -p .",
|
||||
"build:samples": "echo skipped",
|
||||
"build:test": "echo skipped",
|
||||
"check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
|
||||
"clean": "rimraf dist dist-esm test-dist typings *.tgz *.log",
|
||||
"format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
|
||||
"integration-test:browser": "echo skipped",
|
||||
"integration-test:node": "echo skipped",
|
||||
"integration-test": "echo skipped",
|
||||
"lint:fix": "eslint package.json src test --ext .ts --fix --fix-type [problem,suggestion]",
|
||||
"lint": "eslint package.json src test --ext .ts -f html -o storage-blob-perf-test-lintReport.html || exit 0",
|
||||
"pack": "npm pack 2>&1",
|
||||
"prebuild": "npm run clean",
|
||||
"unit-test:browser": "echo skipped",
|
||||
"unit-test:node": "echo skipped",
|
||||
"unit-test": "echo skipped",
|
||||
"test:browser": "echo skipped",
|
||||
"test:node": "echo skipped",
|
||||
"test": "echo skipped"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
# Used in most samples. Retrieve these values from a Cognitive Services instance
|
||||
# in the Azure Portal.
|
||||
ENDPOINT="https://<resource name>.cognitiveservies.azure.com/"
|
||||
TEXT_ANALYTICS_API_KEY="<text analytics api key>"
|
||||
|
||||
# Used to authenticate using Azure AD as a service principal for role-based authentication
|
||||
# in the tokenAuth sample.
|
||||
#
|
||||
# See the documentation for `EnvironmentCredential` at the following link:
|
||||
# https://docs.microsoft.com/javascript/api/@azure/identity/environmentcredential
|
||||
AZURE_TENANT_ID=<AD tenant id or name>
|
||||
AZURE_CLIENT_ID=<ID of the user/service principal to authenticate as>
|
||||
AZURE_CLIENT_SECRET=<client secret used to authenticate to Azure AD>
|
|
@ -0,0 +1,55 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
import {
|
||||
PerfStressTest,
|
||||
PerfStressOptionDictionary,
|
||||
getEnvVar
|
||||
} from "@azure/test-utils-perfstress";
|
||||
import {
|
||||
AzureKeyCredential,
|
||||
TextAnalyticsClient,
|
||||
DetectLanguageOptions
|
||||
} from "@azure/ai-text-analytics";
|
||||
import { TokenCredential, DefaultAzureCredential } from "@azure/identity";
|
||||
|
||||
interface DetectLanguagePerfTestOptions extends DetectLanguageOptions {
|
||||
"documents-count": number;
|
||||
}
|
||||
|
||||
export class DetectLanguageTest extends PerfStressTest<DetectLanguagePerfTestOptions> {
|
||||
options: PerfStressOptionDictionary<DetectLanguagePerfTestOptions> = {
|
||||
"documents-count": {
|
||||
required: true,
|
||||
description: "Number of documents",
|
||||
shortName: "n",
|
||||
longName: "docs-count",
|
||||
defaultValue: 10
|
||||
}
|
||||
};
|
||||
client: TextAnalyticsClient;
|
||||
docs: string[] = [];
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.options = this.parsedOptions;
|
||||
this.docs = Array(this.parsedOptions["documents-count"]?.value!).fill(
|
||||
"Detta är ett dokument skrivet på engelska."
|
||||
);
|
||||
let credential: TokenCredential | AzureKeyCredential;
|
||||
|
||||
try {
|
||||
credential = new DefaultAzureCredential();
|
||||
} catch (e) {
|
||||
credential = new AzureKeyCredential(process.env.TEXT_ANALYTICS_API_KEY ?? "");
|
||||
}
|
||||
|
||||
const endpoint = getEnvVar("ENDPOINT");
|
||||
|
||||
this.client = new TextAnalyticsClient(endpoint, credential);
|
||||
}
|
||||
|
||||
async runAsync(): Promise<void> {
|
||||
await this.client.detectLanguage(this.docs, "en");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
import { PerfStressProgram, selectPerfStressTest } from "@azure/test-utils-perfstress";
|
||||
import { DetectLanguageTest } from "./detectLanguage.spec";
|
||||
|
||||
import dotenv from "dotenv";
|
||||
dotenv.config();
|
||||
|
||||
console.log("=== Starting the perfStress test ===");
|
||||
|
||||
const perfStressProgram = new PerfStressProgram(selectPerfStressTest([DetectLanguageTest]));
|
||||
|
||||
perfStressProgram.run();
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"extends": "../../../../tsconfig.package",
|
||||
"compilerOptions": {
|
||||
"target": "ES2015",
|
||||
"declarationDir": "./typings/latest",
|
||||
"lib": ["ES6", "ESNext.AsyncIterable", "DOM"],
|
||||
"noEmit": true
|
||||
},
|
||||
"compileOnSave": true,
|
||||
"exclude": ["node_modules"],
|
||||
"include": ["./test/**/*.ts"]
|
||||
}
|
Загрузка…
Ссылка в новой задаче