How to schedule two processes if arrival time is same - process

In a single CPU process scheduler, if two processes arrive at the same time in what order will they execute in case of FCFS, SJF, Non preemptive priority and RR?
Below information is given about processes:
{
"Name": "P1",
"ArrivalTime": 0,
"Brust": 10,
"Priority": 3
},
{
"Name": "P2",
"ArrivalTime": 0,
"Brust": 1,
"Priority": 1
},
{
"Name": "P3",
"ArrivalTime": 0,
"Brust": 2,
"Priority": 3
},
{
"Name": "P4",
"ArrivalTime": 0,
"Brust": 1,
"Priority": 4
},
{
"Name": "P5",
"ArrivalTime": 0,
"Brust": 5,
"Priority": 2
}

Technically speaking, 2 processes can not arrive at the exact same time. Arrival of a process means that the process (PCB) is added to a queue (any scheduling algorithm basically reads / writes / updates this queue and / or it's elements). Now, when you are modifying data structures like a queue, you will add one element at a time (in a multi-threaded environment, the processes which add elements to the queue would be synchronized). HTH.

Related

How add values in JSON to get a cumulative total using Dataweave

I have a json object that has the memory, cpu and number of replicas for each API in the system.
I need to calculate the total CPU and Memory where the CPU / Memory for each API is cpu * number fo replicas. Take a look at the following input JSON
var payload = [
{
"id": "5a9b06b3-ed2c-4382-cf41427b6f56",
"name": "api-1",
"cpuReserved": 0.2,
"cpuLimit": 0.5,
"memReserved": 2,
"memLimit": 2,
"replicas": 1,
"status": "RUNNING"
},
{
"id": "79a90d5e-d042-9a6c-61cbe1341d04",
"name": "api-2",
"cpuReserved": 0.2,
"cpuLimit": 1,
"memReserved": 2,
"memLimit": 2,
"replicas": 2,
"status": "RUNNING"
},
{
"id": "15d0e51f-198c-948c-c4c864a5dd72",
"name": "api-3",
"cpuReserved": 0.2,
"cpuLimit": 0.5,
"memReserved": 2,
"memLimit": 2,
"replicas": 1,
"status": "RUNNING"
}
]
The output required is something like this:
"report": {
"count": 3,
"totalCPULimit": 3,
"totalCPUReserved": 0.8,
"totalMemReserved": 8,
"totalMemLimit": 8
}
Note: out of the 3 APIS in the input; 1 API has 2 replicas while the other 2 APIs have 1 replica each.
How can I generate this output using Dataweave in MuleSoft 4?
Pretty crude though it can get you to the desired:
%dw 2.0
output application/json
var totals = payload map {
a: $.cpuLimit * $.replicas,
b: $.cpuReserved * $.replicas,
c: $.memReserved * $.replicas,
d: $.memLimit *$.replicas
}
---
"report": {
"count": sizeOf(payload),
"totalCPULimit": sum(totals.a),
"totalCPUReserved": sum(totals.b),
"totalMemReserved": sum(totals.c),
"totalMemLimit": sum(totals.d),
}
I found another way of doing it deriving from an XML transformation code
%dw 2.0
output application/json
---
"report": {
"count": sizeOf(payload) as String,
"totalCPULimit": sum(payload map($.cpuLimit * $.replicas)),
"totalCPUReserved": sum(payload map($.cpuReserved * $.replicas)),
"totalMemReserved": sum(payload map($.memReserved * $.replicas)),
"totalMemLimit": sum(payload map($.memLimit * $.replicas)),
}
]

Great Expectations Row Based Dimensions

I have data like this:
[ {
"name": "Apple",
"price": 1,
"type": "Food"
},
{
"name": "Apple",
"price": 0.90,
"type": "Food"
},
{
"name": "Apple",
"price": 1000,
"type": "Computer"
},
{
"name": "Apple",
"price": 900,
"type": "Computer"
}
]
Using the Great Expectations automatic profile, a valid range for price would be 0.90 to 1,000. Is it possible to have it slice on the type dimension, so food would be 0.90 to 1 and computer would be 900 to 1000? Or would I need to transform the data first using dbt? I know the column that will create the dimension, but I don't know the particular values.
Also, same question on differences between rows. Like if they had a timestamp, instead of 900 to 1000, it validates -100 for the change in value.
I used this approach to first load the data in a pandas data frame:
https://discuss.greatexpectations.io/t/how-can-i-use-the-return-format-unexpected-index-list-to-select-row-from-a-pandasdataset/70/2

Azure Data Factory JSON syntax

In Azure Data Factory, I have a copy activity. The data source is the response body from a REST API POST request.
The sink is a SQL table. The problem is that, even though my JSON data contains multiple rows, only the first row is getting copied.
The source data looks like the following:
{
"offset": 0,
"limit": 1000,
"total": 65,
"loaded": 34,
"unloaded": 31,
"cubeCaches": [
{
"id": "MxMUVDN0Q1MzAk5MDg6RDkxREQxMUU5RDBDNzR2NMTk6YWNsZGxwMTJtc3QuY2952aXppZW50aW5==",
"projectId": "15D91DD11E9D0C74B3319",
"source": {
"name": "12302021",
"id": "07EF95111EC7F954158",
"type": "cube"
},
"state": {
"active": true,
"dirty": false,
"infoDirty": false,
"persisted": true,
"processing": false,
"loadedState": "loaded"
},
"lastUpdateTime": "2022-01-24T14:22:30Z",
"lastHitTime": "2022-02-14T20:02:02Z",
"hitCount": 1,
"size": 798720,
"creatorId": "D4E8BFD56085",
"lastUpdateJob": 18937,
"openViewCount": 0,
"creationTime": "2022-01-24T15:07:24Z",
"historicHitCount": 22,
"dataLanguages": [],
"rowCount": 2726,
"columnCount": 9
},
{
"id": "UYwMTIxMUFNjkxMUU5RDBDMTRCNkMwMDgwRUYzNUQ0MUI6YWNsZjLmNvbQ==",
"projectId": "120D0C1480EF35D41B",
"source": {
"name": "All Clients (YTD)",
"id": "49E5B13466251CD0B54E8F",
"type": "cube"
},
"state": {
"active": true,
"dirty": false,
"infoDirty": false,
"persisted": true,
"processing": false,
"loadedState": "loaded"
},
"lastUpdateTime": "2022-01-03T01:00:01Z",
"hitCount": 0,
"size": 82488152,
"creatorId": "1E2AFB011E80EF35FF14",
"lastUpdateJob": 364091,
"openViewCount": 0,
"creationTime": "2022-02-14T01:04:55Z",
"historicHitCount": 0,
"dataLanguages": [],
"rowCount": 8146903,
"columnCount": 13
}
}
I want to add a row in the Sink table (SQL) for every "id" in the JSON. However, when I run the activity, only the first record gets copied. It's mapped correctly, but I want it to copy all rows in the JSON, not just 1.
My Mapping tab in Azure Data Factory looks like this:
What am I doing wrong here? I'm thinking there is something wrong with my "Source" syntax for each of the columns...
In $cubeCashes[0][...] you're explicitly mapping the first element from this array into columns, and that's why only one row lands in the Sink.
I don’t know a way to achieve what you intend with copy activity only. I would use the Mapping Data Flow here, and inlide I would flatten (Flatten activity) your data to get the array of objects.
Then from this flattened dataset you could use a Derived Column to map the fields in JSON into columns of your target, Select, to remove unwanted original fields, and Sink it into your target location.

Scale Fargate service tasks to match CloudWatch metric

I'm using CloudWatch Metric Math to calculate the number of workers (tasks) that I want my Fargate service to be scaled to. I planned on creating an alarm in CloudWatch to trigger the scaling action once it rose above or below the target number of 0. However, it doesn't look like there a way I can create an alarm based on CloudWatch Metric Math - or an alarm that does any type of comparison between two numbers (number of tasks needed vs. number of tasks existing).
How can I setup a Fargate scaling policy to scale based on my existing metric of 'Workers Needed'.
Metric Math
Formula: m1-m2-3 == desired scale offset
m1: Active Workers (tasks)
m2: Workers Needed (tasks)
{
"type": "metric",
"x": 0,
"y": 0,
"width": 24,
"height": 6,
"properties": {
"metrics": [
[ { "expression": "m1-m2-3", "label": "Workers/Needed difference", "id": "e1" } ],
[ "AWS/ECS", "MemoryUtilization", "ServiceName", "worker-service", "ClusterName", "my-cluster", { "period": 60, "stat": "SampleCount", "id": "m1", "label": "Active Workers" } ],
[ "LogMetrics", "Workers Needed", { "period": 60, "stat": "Maximum", "id": "m2" } ]
],
"view": "timeSeries",
"stacked": false,
"region": "us-east-1",
"title": "Worker/Lab difference",
"period": 300
}
}
Edit: Alarms based on metric math is now a thing
This doc page about metric math doesn't mention alarms at all, expressions seem to be more about visualizing with a dashboard. I also don't see anything about metric math in the SDK or cli documentation as far as alarms are concerned.
Your next simplest solution is probably paying homage to the great catch-all of all shortcomings of AWS, and write a Lambda that pulls the metrics, does the calculation, then publishes the metric as a custom metric with PutMetric. You can trigger this with a CloudWatch Event if you want a cron-like thing, or many, many other things by integrating it with SNS or just invoking it directly.
It's not the answer you want, but unfortunately I think it's the simplest way to get the functionality you want.

How to get API usage data from Azure API Management?

We are trying to collect some reports about how our API is used by customers. We use Azure API Management, and I can see that in API Management portal such data exist, I can see what I need to know going to portal in Admin>Activity section. Like how many calls individual user made for particular API, and I can filter it by date.
Question: How to get this data out of the system. Preferable using some API to have continues export. But, even manually?
The API to get request level analytics is
GET https://management.azure.com/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.ApiManagement/service/apimService1/reports/byRequest?$filter=timestamp ge datetime'2017-06-01T00:00:00' and timestamp le datetime'2017-06-04T00:00:00'&api-version=2017-03-01
The response includes the ApiId, OperationId, UserId, his subscriptionId to the Product etc, which might be beneficial to you.
{
"value": [
{
"apiId": "/apis/5931a75ae4bbd512a88c680b",
"operationId": "/apis/5931a75ae4bbd512a88c680b/operations/-",
"productId": "/products/-",
"userId": "/users/1",
"method": "GET",
"url": "https://apimService1.azure-api.net/echo/resource?param1=sample",
"ipAddress": "207.xx.155.xx",
"responseCode": 404,
"responseSize": 405,
"timestamp": "2017-06-03T00:17:00.1649134Z",
"cache": "none",
"apiTime": 221.1544,
"serviceTime": 0,
"apiRegion": "East Asia",
"subscriptionId": "/subscriptions/5600b59475ff190048070002",
"requestId": "63e7119c-26aa-433c-96d7-f6f3267ff52f",
"requestSize": 0
}]
}
Check this out Reports_ByRequest
Also, check the Azure monitor integration
For those who are looking for aggregate usage by user (perhaps for monetization) - there is a "byUser" endpoint as well. The request is structured like below:
https://{api-service-name}.management.azure-api.net/subscriptions/{subscription}/resourceGroups/{resource-group}/providers/Microsoft.ApiManagement/service/{api-service-name}/reports/byUser?$filter=timestamp ge datetime'2019-12-01T00:00:00' and timestamp le datetime'2019-12-04T00:00:00'&api-version=2017-03-01
The documentation says to make a request to "https://management.azure-api.net/[...]" but I had to prepend the resource name like in the request above.
And the response:
{
"value": [
{
"name": "Administrator",
"userId": "/users/1",
"callCountSuccess": 13,
"callCountBlocked": 1,
"callCountFailed": 0,
"callCountOther": 0,
"callCountTotal": 14,
"bandwidth": 11019,
"cacheHitCount": 0,
"cacheMissCount": 0,
"apiTimeAvg": 1015.7607923076923,
"apiTimeMin": 330.3206,
"apiTimeMax": 1819.2173,
"serviceTimeAvg": 957.094776923077,
"serviceTimeMin": 215.24,
"serviceTimeMax": 1697.3612
},
{
"name": "Samir Solanki",
"userId": "/users/56eaec62baf08b06e46d27fd",
"callCountSuccess": 0,
"callCountBlocked": 0,
"callCountFailed": 0,
"callCountOther": 0,
"callCountTotal": 0,
"bandwidth": 0,
"cacheHitCount": 0,
"cacheMissCount": 0,
"apiTimeAvg": 0,
"apiTimeMin": 0,
"apiTimeMax": 0,
"serviceTimeAvg": 0,
"serviceTimeMin": 0,
"serviceTimeMax": 0
},
{
"name": "Anonymous",
"userId": "/users/54c800b332965a0035030000",
"callCountSuccess": 0,
"callCountBlocked": 0,
"callCountFailed": 0,
"callCountOther": 0,
"callCountTotal": 0,
"bandwidth": 0,
"cacheHitCount": 0,
"cacheMissCount": 0,
"apiTimeAvg": 0,
"apiTimeMin": 0,
"apiTimeMax": 0,
"serviceTimeAvg": 0,
"serviceTimeMin": 0,
"serviceTimeMax": 0
}
],
"count": 3,
"nextLink": ""
}
If you need to filter by type of request or API, you can do that as well - List by User