Azure-Samples / Iot-Telemetry-Simulator

The IoT Telemetry Simulator allows you to test Azure IoT Hub or Eventhub ingestion at scale. The implementation is communicating with Azure IoT Hub using multiplexed AMQP connections. An automation library allows you to run it as load test as part of a CI/CD pipeline.
MIT License
67 stars 49 forks source link

Zeros produced instead of random values #6

Closed algattik closed 3 years ago

algattik commented 3 years ago

Please provide us with the following information:

This issue is for a: (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Ran the dockerhub image with:

DeviceCount=1000
DeviceIndex=0
Template={ "eventId": "$.Guid", "complexData": { "moreData0": $.moreData00, "moreData1": $.moreData01, "moreData2": $.moreData02, "moreData3": $.moreData03, "moreData4": $.moreData04, "moreData5": $.moreData05, "moreData6": $.moreData06, "moreData7": $.moreData07, "moreData8": $.moreData08, "moreData9": $.moreData09, "moreData10": $.moreData10, "moreData11": $.moreData11, "moreData12": $.moreData12, "moreData13": $.moreData13, "moreData14": $.moreData14, "moreData15": $.moreData15, "moreData16": $.moreData16, "moreData17": $.moreData17, "moreData18": $.moreData18, "moreData19": $.moreData19 }, "value": $.value, "deviceId": "$.DeviceId", "deviceSequenceNumber": $.Counter, "type": "$.type", "createdAt": "$.Time" }
Interval=1000
DevicePrefix=contoso-device-id-
MessageCount=0
Variables=[ {"name": "value", "random": true}, {"name": "moreData00", "random": true}, {"name": "moreData01", "random": true}, {"name": "moreData02", "random": true}, {"name": "moreData03", "random": true}, {"name": "moreData04", "random": true}, {"name": "moreData05", "random": true}, {"name": "moreData06", "random": true}, {"name": "moreData07", "random": true}, {"name": "moreData08", "random": true}, {"name": "moreData09", "random": true}, {"name": "moreData10", "random": true}, {"name": "moreData11", "random": true}, {"name": "moreData12", "random": true}, {"name": "moreData13", "random": true}, {"name": "moreData14", "random": true}, {"name": "moreData15", "random": true}, {"name": "moreData16", "random": true}, {"name": "moreData17", "random": true}, {"name": "moreData18", "random": true}, {"name": "moreData19", "random": true}, {"name": "Counter", "min": 0}, {"name": "type", "values": ["TEMP", "CO2"]} ]
IotHubConnectionString=HostName=iot-xxxx.azure-devices.net;SharedAccessKeyName=device;SharedAccessKey=xxxx

Accessing the IoT Hub Event Hubs endpoint shows a mixture of events with properly populated random values, and events where all random values are 0:

Received event from partition: 3.
{ body: '{
    "eventId": "1be879b9-0b32-4026-97aa-aafc38ddfbf1",
    "complexData": {
        "moreData0": 176772633,
        "moreData1": 1713618591,
        "moreData2": 851733976,
        "moreData3": 1045725759,
        "moreData4": 814559650,
        "moreData5": 698850308,
        "moreData6": 1227999053,
        "moreData7": 1833559892,
        "moreData8": 229729420,
        "moreData9": 703205628,
        "moreData10": 1724511707,
        "moreData11": 576329261,
        "moreData12": 783146766,
        "moreData13": 1257494123,
        "moreData14": 339609237,
        "moreData15": 1538624322,
        "moreData16": 634618423,
        "moreData17": 789017563,
        "moreData18": 1310816339,
        "moreData19": 1813005905
    },
    "value": 476772162,
    "deviceId": "contoso-device-id-000547",
    "deviceSequenceNumber": 38,
    "type": "TEMP",
    "createdAt": "2021-01-01T06:58:00.7419466Z"
}
', properties: {}, offset: 2486798103976, sequence_number: 16522817, enqueued_time=datetime.datetime(2021, 1, 1, 6, 58, 0, 744000, tzinfo=datetime.timezone.utc) }
Received event from partition: 1.
{ body: '{
    "eventId": "3c4dd67c-e782-4d00-be7f-5ac4f079c31f",
    "complexData": {
        "moreData0": 0,
        "moreData1": 0,
        "moreData2": 0,
        "moreData3": 0,
        "moreData4": 0,
        "moreData5": 0,
        "moreData6": 0,
        "moreData7": 0,
        "moreData8": 0,
        "moreData9": 0,
        "moreData10": 0,
        "moreData11": 0,
        "moreData12": 0,
        "moreData13": 0,
        "moreData14": 0,
        "moreData15": 0,
        "moreData16": 0,
        "moreData17": 0,
        "moreData18": 0,
        "moreData19": 0
    },
    "value": 0,
    "deviceId": "contoso-device-id-000363",
    "deviceSequenceNumber": 47,
    "type": "TEMP",
    "createdAt": "2021-01-01T06:58:11.2374109Z"
}
'

OS and Version?

Current Dockerhub image

Versions

Mention any other details that might be useful

This is probably related to sharing a single Random instance in the TelemetryValues class

https://stackoverflow.com/questions/3049467/is-c-sharp-random-number-generator-thread-safe

No, using the same instance from multiple threads can cause it to break and return all 0's.