title,body,link,tags,view_count,is_answered,score,answer_count
Hibernate ConcurrentModificationException problem in Stress testing,"<p>There is an application with the following configuration:</p>
<p>1- HK2 for DI</p>
<p>2- Hibernate for ORM</p>
<p>and</p>
<p>3- GrizzlyHttpServer</p>
<p>and the its hibernate configuration is :</p>
<pre><code>import org.hibernate.*;
import org.hibernate.boot.*;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.jvnet.hk2.annotations.Service;

@Service
public class HibernateOracle {
    private Session session;
    private SessionFactory factory;

    public HibernateOracle() {
        final StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure() // configures settings from hibernate.cfg.xml
                .build();
        factory = new MetadataSources(registry).addPackage(&quot;com.art.entity&quot;).buildMetadata().buildSessionFactory();
        session = factory.openSession();
    }

    public Session getSession() {
        if (session == null || !session.isOpen())
            session = factory.openSession();
        return this.session;
    }


}
</code></pre>
<p>and the one method of a repository file is:</p>
<pre><code>@jakarta.inject.Inject
private HibernateOracle hibernateOracle;

@Override
    public User get(String username) throws UserNotFoundException {
        Session session = hibernateOracle.getSession();
        try {
            return (User) session.createNamedQuery(&quot;User.findOneByUserName&quot;)
                    .setParameter(&quot;username&quot;, username).getSingleResult();
        } catch (Exception e) {
            e.printStackTrace();
            throw new UserNotFoundException();
        } finally {
            //
        }
    }
</code></pre>
<p>It is worked correctly in the normal state but when the application is tested by such as load-test the following exception is raised in this method:</p>
<blockquote>
<p>java.util.ConcurrentModificationException     at
java.base/java.util.HashMap.forEach(HashMap.java:1424)    at
org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl.releaseResources(ResourceRegistryStandardImpl.java:328)
at
org.hibernate.resource.jdbc.internal.AbstractLogicalConnectionImplementor.afterTransaction(AbstractLogicalConnectionImplementor.java:60)
at
org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.afterTransaction(LogicalConnectionManagedImpl.java:167)
at
org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.afterTransaction(JdbcCoordinatorImpl.java:276)
at
org.hibernate.internal.SessionImpl.afterOperation(SessionImpl.java:550)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1464)   at
org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1649)
at
org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1617)
at
org.hibernate.query.internal.AbstractProducedQuery.getSingleResult(AbstractProducedQuery.java:1665)
at
com.art.vesal.backend.core.dao.impl.UserDaoImpl.get(UserDaoImpl.java:238)
at
com.art.vesal.backend.core.controller.customer_management.UserControllerImpl.get(UserControllerImpl.java:159)
at
com.art.vesal.backend.core.controller.customer_management.CustomerControllerImpl.checkCustomer(CustomerControllerImpl.java:598)
at
com.art.vesal.backend.core.controller.messaging.MTSMSControllerImpl.sendMessageManyToMany(MTSMSControllerImpl.java:282)
at
com.art.vesal.backend.core.controller.messaging.ArtMTSMSImpl.sendMessageManyToMany(ArtMTSMSImpl.java:140)
at
com.art.vesal.backend.core.controller.rest.MessageRelayRest.sendMessageManyToMany(MessageRelayRest.java:26)
at jdk.internal.reflect.GeneratedMethodAccessor35.invoke(Unknown
Source)   at
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)   at
org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$0(ResourceMethodInvocationHandlerFactory.java:52)
at
org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:124)
at
org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:167)
at
org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:219)
at
org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:79)
at
org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:475)
at
org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:397)
at
org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:81)
at
org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:255)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:248)     at
org.glassfish.jersey.internal.Errors$1.call(Errors.java:244)  at
org.glassfish.jersey.internal.Errors.process(Errors.java:292)     at
org.glassfish.jersey.internal.Errors.process(Errors.java:274)     at
org.glassfish.jersey.internal.Errors.process(Errors.java:244)     at
org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:265)
at
org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:234)
at
org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:680)
at
org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.service(GrizzlyHttpContainer.java:356)
at
org.glassfish.grizzly.http.server.HttpHandler$1.run(HttpHandler.java:190)
at
org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:535)
at
org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:515)
at java.base/java.lang.Thread.run(Thread.java:833)</p>
</blockquote>
<p>Where is the problem and how do I fix it such hibernate connection polling and so on?</p>
",https://stackoverflow.com/questions/75593594/hibernate-concurrentmodificationexception-problem-in-stress-testing,"['java', 'hibernate', 'java.util.concurrent']",83,False,0,1
Optimize laravel rest api for stress testing,"<p>i have a restful project when make stress test with maximum 500 users the route return status:error
i tried to optimize laravel query and decrease the amount of data which received at every request
but the result of performance not shown</p>
<p>so the question how to optimize my proeject and what are helpfull tools i can use to make best performance as possible</p>
<ul>
<li>Replace whereHas and whereDoesntHave with whereIn &amp; whereNotIn</li>
<li>remove appends from model</li>
<li>return used data only and remove extra data from responses</li>
</ul>
",https://stackoverflow.com/questions/74999248/optimize-laravel-rest-api-for-stress-testing,"['php', 'laravel', 'performance']",194,True,0,2
stress testing of models having nested UDT cassandra,"<p>I have a model having nested UDT. How to perform stress testing for models.</p>
<p>cassandra version: 4.1</p>
<p>I have tried changing the data type to string, but can we conclude on result?</p>
",https://stackoverflow.com/questions/75884319/stress-testing-of-models-having-nested-udt-cassandra,"['cassandra', 'datastax', 'cassandra-stress', 'nosqlbench']",27,False,0,0
Parallel Stress Testing using Gatling using message passing between scenarios,"<p>Considering those pseudo rest APIs:</p>
<ul>
<li>User creation: It gives me back a token to use for authentication</li>
<li>Post creation: It takes the id of the user previously created</li>
<li>Like: It takes the id of the user and the id of the post</li>
<li>Comment: It takes the id of the post and the user (plus a message)</li>
</ul>
<p>It seems to me not very straight forward from a Gatling point of view creating those step in an asynchronous way.
I expect to have something that creates users, let's say 100 and in the meantime something else that was taking all the created user randomly until that moment and create posts. Something else that was waiting to have post to put likes and comments.
Is it possible to do it on fly? I mean without having all the data since the very beginning of the execution or without waiting for the user creation scenario?</p>
<p>My current implementation seems quite odd to me and doesn't really reflect what I had in mind</p>
<pre class=""lang-kotlin prettyprint-override""><code>
class MySimulation : Simulation() {

    val createdUsers = ConcurrentHashMap&lt;String, String&gt;()

    val services = http
        .baseUrl(&quot;https://services-something.com&quot;)
        .doNotTrackHeader(&quot;1&quot;)
        .acceptLanguageHeader(&quot;en-US,en;q=0.5&quot;)
        .acceptEncodingHeader(&quot;gzip, deflate&quot;)
        .contentTypeHeader(&quot;application/json&quot;)
        .acceptHeader(&quot;application/json&quot;)

    val userTokens = ConcurrentHashMap&lt;String, String&gt;()

    val users = scenario(&quot;User Creation&quot;)
        .feed(csv(&quot;data/users.csv&quot;, '&quot;').random())
        .exec(
            createUser()
                .check(
                    status().shouldBe(200),
                    jsonPath(&quot;$.result.token.token&quot;).saveAs(&quot;userToken&quot;),
                    jsonPath(&quot;$.result.userInfo.uid&quot;).saveAs(&quot;userId&quot;),
                )
        )
        .exec { session -&gt;
            // Think about a different approach
            val userToken = session.get&lt;String&gt;(&quot;userToken&quot;) ?: &quot;&quot;
            val userId = session.get&lt;String&gt;(&quot;userId&quot;) ?: &quot;&quot;
            userTokens[userId] = userToken
            session
        }
        .pause(1)


    // This is a sort of hand made rotation feeder for users
    private fun availableUsers(userHashMap: ConcurrentHashMap&lt;String, String&gt;) = sequence {
        while (true) {
            yieldAll(userHashMap.map { entry -&gt; mapOf(&quot;userId&quot; to entry.key, &quot;userToken&quot; to entry.value) })
        }
    }

    init {
        setUp(
            users.injectOpen(rampUsers(10).during(10))
                .andThen(
                    scenario(&quot;Post creation&quot;)
                        .feed(availableUsers(userTokens).iterator())
                        .exec(
                            createPostWithHashTag(&quot;#{userToken}&quot;)
                        )
                        .injectOpen(
                            rampUsers(30).during(40)
                        )
                )
        ).protocols(services)
    }
}

</code></pre>
<p>This implementation has many problems.</p>
<ol>
<li>It creates users in a sync block before the &quot;Post creation&quot; scenario</li>
<li>It can not continue to distribute the user creation through the full execution of the stress test (creating new users and keep posting and liking)</li>
</ol>
<p>Is it correct to think about those scenarios in parallel using Gatling? Is it a correct approach in gatling to have a sort of message passing between those, like a pub sub feeder?
I guess a blocking feeder (waiting for data from the) is not the correct approach due to the fact it would change the expected user/operations threshold given into initial parameters (like rampUser(10).during(100))</p>
<p>Do you have any example of something parallel that creates users and start to create other resources from those specifying the number of the users and a different number of resources created in parallel?</p>
",https://stackoverflow.com/questions/76202483/parallel-stress-testing-using-gatling-using-message-passing-between-scenarios,"['gatling', 'stress-testing']",15,False,0,0
stress testing of models having nested UDT cassandra,"<p>I have a model having nested UDT. How to perform stress testing for models.</p>
<p>cassandra version: 4.1</p>
<p>I have tried changing the data type to string, but can we conclude on result?</p>
",https://stackoverflow.com/questions/75884319/stress-testing-of-models-having-nested-udt-cassandra,"['cassandra', 'datastax', 'cassandra-stress', 'nosqlbench']",27,False,0,0
Why the Task gets Cancelled,"<p>I'd like to spawn some threads and in each thread sequentially make calls to an API and aggregate the results (some sort of stress testing). Here is my attempt:</p>
<pre><code>private async Task DoWork()
{
    var allResponses = new List&lt;int&gt;();
    for (int i = 0; i &lt; 10; i++)
    {
        await Task.Run(() =&gt;
        {
            var responses = Enumerable.Range(0, 50).Select(i =&gt; CallApiAndGetStatusCode());
            allResponses.AddRange(responses);
        });
    }

    // do more work
}


private int CallApiAndGetStatusCode()
{
    try
    {
        var request = new HttpRequestMessage(httpMethod.Get, &quot;some url&quot;);

        var responseResult = httpClient.SendAsync(request).Result;
        return (int)responseResult.StatusCode;
    }
    catch (Exception e)
    {
        logger.LogError(e, &quot;Calling API failed&quot;);
    }
}
</code></pre>
<p>However, this code always ends up the <code>catch</code> with the inner exception being <code>{&quot;A task was canceled.&quot;}</code>. What am I doing wrong here?</p>
",https://stackoverflow.com/questions/75343591/why-the-task-gets-cancelled,"['c#', 'task']",124,True,0,2
Email Attribute not reappearing after incorrect email input,"<p><a href=""https://i.stack.imgur.com/UIfW3.png"" rel=""nofollow noreferrer"">enter image description here</a></p>
<p>See above image. We are stress testing the email input and putting in incorrect values. Once we click submit on send verification code, it shows the error message, but the email box does not reappear.</p>
<p>We tried reuploading the policies and checking the base for anything that may cause this error</p>
",https://stackoverflow.com/questions/75595636/email-attribute-not-reappearing-after-incorrect-email-input,"['azure-ad-b2c', 'attributeerror', 'azure-ad-b2c-custom-policy', 'claims', 'azure-b2c']",23,False,0,0
List index out of range (Fractional Knapsack),"<p>I'm attempting to implement a greedy algorithm for the fractional knapsack problem for a coursera assignment. The course insists on not giving the inputs that cause the problem. Below is my code of the solution and the code I used for stress testing.</p>
<pre><code>def optimal_value(capacity, weights, values):
    value = 0.

    while capacity &gt; 0 and len(values) &gt; 0:
        maxval = 0

        # I need values per weight
        prices = [val / wei for val, wei in zip(values, weights)]

        for i in range(len(prices)):
            if prices[i] &gt; maxval:
                maxval = prices[i]
                best_item = i

        # put as much of the best item into the pack as we can and update the value
        added = min(capacity, weights[best_item])
        value += (added / weights[best_item]) * values[best_item]
        capacity += -added

        #print(f&quot;prices are {prices}, values are {values}, best item is {best_item}&quot;)
        #print(f&quot;value is {value}, added is {added}, capacity is {capacity}&quot;)

        if added == weights[best_item]:
            # we used up the best option
            values = [val for i, val in enumerate(values) if i != best_item]
            weights = [weight for i, weight in enumerate(
                weights) if i != best_item]

    return value
</code></pre>
<pre><code>import numpy as np

def create_knapsack_test_case():
    capacity = np.random.randint(0, 2e6)
    n = np.random.randint(1, 1000)
    weights = np.random.randint(1, 2e6, n)
    values = np.random.randint(0, 2e6, n)

    return capacity, weights, values

for i in range(20000):
    try:
        inputs = create_knapsack_test_case()
        opt = optimal_value(*inputs)
    except:
        print(f&quot;faulty inputs are {inputs}&quot;)
</code></pre>
<p>I'm missing an edge case and have no idea what it could be. Please help.</p>
",https://stackoverflow.com/questions/75312974/list-index-out-of-range-fractional-knapsack,"['python', 'greedy']",29,False,0,0
How do I find out how Helidon MP decides on the number of concurrent threads to process,"<p>While stress testing our microservice build on Helidon MP, we found that the waiting time for the threads in handling requests increased linearly. We wanted to understand how Helidon MP decides on how many concurrent threads to create in its pool to manage incoming requests. Is it proportional to the number of cpu cores? Can I tweak/configure it?</p>
<p>Stress tested using JMeter sending 3 requests/second for 30 seconds.</p>
",https://stackoverflow.com/questions/75115932/how-do-i-find-out-how-helidon-mp-decides-on-the-number-of-concurrent-threads-to,"['multithreading', 'concurrency', 'request', 'helidon']",144,True,4,1
Why I see only 100 maxmimum total concurrent requests whem the limit is 1000?,"<p><a href=""https://i.stack.imgur.com/P5Qfo.jpg"" rel=""nofollow noreferrer"">Graphic</a>
<a href=""https://i.stack.imgur.com/fKoVd.jpg"" rel=""nofollow noreferrer"">Invocations</a></p>
<p>By default amazon says that there are can be 1000 instances for free plan.</p>
<p>But when i've write a highload stress-testing with multiple requests at the same time, only 100 instances are allocated. Why this is happen?</p>
<p>I've expect that all 1000 instances will be allocated in free plan.</p>
<p>There is config file:</p>
<pre class=""lang-yaml prettyprint-override""><code>AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31

Globals:
  Function:
    Timeout: 50
    MemorySize: 3000
    Tracing: Active
  Api:
    TracingEnabled: true

Resources:
  InferenceFunction:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      PackageType: Image
      Architectures:
      - x86_64
      Events:
        Inference:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            Path: /predict
            Method: post
    Metadata:
      Dockerfile: Dockerfile
      DockerContext: ./app
      DockerTag: python3.9-v1

  ApplicationResourceGroup:
    Type: AWS::ResourceGroups::Group
    Properties:
      Name:
        Fn::Join:
        - ''
        - - ApplicationInsights-SAM-
          - Ref: AWS::StackName
      ResourceQuery:
        Type: CLOUDFORMATION_STACK_1_0
  ApplicationInsightsMonitoring:
    Type: AWS::ApplicationInsights::Application
    Properties:
      ResourceGroupName:
        Fn::Join:
        - ''
        - - ApplicationInsights-SAM-
          - Ref: AWS::StackName
      AutoConfigurationEnabled: 'true'
    DependsOn: ApplicationResourceGroup
Outputs:
  # ServerlessRestApi is an implicit API created out of Events key under Serverless::Function
  # Find out more about other implicit resources you can reference within SAM
  # https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api
  InferenceApi:
    Description: API Gateway endpoint URL for Prod stage for Inference function
    Value: !Sub &quot;https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/predict/&quot;
  InferenceFunction:
    Description: Inference Lambda Function ARN
    Value: !GetAtt InferenceFunction.Arn
  InferenceFunctionIamRole:
    Description: Implicit IAM Role created for Inference function
    Value: !GetAtt InferenceFunctionRole.Arn
</code></pre>
<p>There is Python AWS Lambda handler</p>
<pre class=""lang-py prettyprint-override""><code>import json

from analyzer.model import Model

model_file = '/opt/ml/model'
model = Model(model_file, device=&quot;cpu&quot;)


def lambda_handler(event, context):
    sample = event['body']
    result =model(sample)

    return {
        'statusCode': 200,
        'body': json.dumps(
            {
                &quot;predicted_label&quot;: result.value
            }
        )
    }
</code></pre>
<p>There is Docker file</p>
<pre><code>FROM public.ecr.aws/lambda/python:3.9

COPY . .

RUN python3.9 -m pip install -r requirements.txt -t .

CMD [&quot;app.lambda_handler&quot;]
</code></pre>
",https://stackoverflow.com/questions/75421528/why-i-see-only-100-maxmimum-total-concurrent-requests-whem-the-limit-is-1000,"['python', 'amazon-web-services', 'aws-lambda', 'instance']",54,False,1,1
Chartjs-node-canvas heap out of memory,"<p>I am running this code in a NodeJS Server. The idea is to create charts to insert in PDF with PDFMake.</p>
<p>Stress Testing it, reaches Heap Out of Memory.</p>
<p>So, I wonder if there is a way of configuring the NodeJS API to avoid this problem.
Or improving the code...</p>
<pre class=""lang-js prettyprint-override""><code>   let chartJSNodeCanvas = new ChartJSNodeCanvas({ width: 800, height: 600 }); 
    
    Chart.defaults.animation = false;
    Chart.defaults.responsive = false;

    const chartBody: ChartConfiguration = req.body['chart'];
    const width: number = req.body['pageWidth'];
    const height: number = req.body['pageHeight'];


    chartJSNodeCanvas = new ChartJSNodeCanvas({ width, height }); 
        
    const result = await chartJSNodeCanvas.renderToBuffer(chartBody);
    return res.end(result);
</code></pre>
<p><strong>PS.: Generating Charts on Server Side is a little difficult. So if there is a better solution, less memory wasting and FREE, it would help a lot.</strong></p>
",https://stackoverflow.com/questions/75688918/chartjs-node-canvas-heap-out-of-memory,"['node.js', 'chart.js']",75,False,0,0
How to estimate the CPU/memory needed for a backend app? How do you do it? Or is this just impossible?,"<p>I need to estimate the server (CPU/memory) needed for my backend app. I would appreciate it if I could know how to do that.</p>
<p>If you are interested, here are my (failed) attempts:</p>
<p>Thought 1: Stress testing. The problem is that it seems hard to estimate the following quantities without a large error. For example DAU, average QPS, QPS peak, request distribution (e.g. how many people are requesting the hot data?), data size, data distribution (e.g. what is the working set size?). Then, suppose I have a 2x error on every single item, and I have 5 items that are multiplied together, then I will have a 32x error which is huge. Even if the stress testing is perfect, I already have a 32x error because the estimation of the quantities is coarse.</p>
<p>Thought 2: Look at the resources needed for similar backends. Even if I find such &quot;similar&quot; backends, IMHO it is still hard because: For example, different language (Java/Go/Python/...) can be a lot faster/slower; they can have different implementation or complexity; the code contains different (slow) SQLs; they can have a different amount of data; the QPS can be different; etc.</p>
<p>Hopefully, my thoughts are wrong or there are other methods!</p>
",https://stackoverflow.com/questions/75384992/how-to-estimate-the-cpu-memory-needed-for-a-backend-app-how-do-you-do-it-or-is,"['performance', 'memory', 'performance-testing', 'cpu', 'estimation']",40,False,0,0
Does it make sense to stress test a cloud system that can autoscale?,"<p>From k6 <a href=""https://k6.io/docs/test-types/stress-testing/"" rel=""nofollow noreferrer"">https://k6.io/docs/test-types/stress-testing/</a></p>
<p>It says that a stress test is used to check a system's capacity by pushing it to the breaking point. The article has an example to test for scaling up and down but the graph does not show any failed requests.</p>
<p>My question is, if the system can scale up in the cloud indefinitely, then it seems it does not have a breaking point, so in this case is it really a stress test? Would it be more appropriate to call that a scalability test? Or are the two basically the same thing?</p>
",https://stackoverflow.com/questions/74979988/does-it-make-sense-to-stress-test-a-cloud-system-that-can-autoscale,"['stress-testing', 'k6']",53,False,0,1
Unable to bulk import devices with Private Storage account,"<p>I am working on stress testing for our IoT Usecase.</p>
<p>For testing, I need to create 100 devices.
So, I have developed one azure function to use IoTHubs Import Device feature as per <a href=""https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-bulk-identity-mgmt#import-devices"" rel=""nofollow noreferrer"">MSFT docs</a>.</p>
<p>When I used, sample code using Public Storage account for Import/Output blob container SAS token.
It worked as per expectation and created devices on IoTHub.</p>
<p>But when I am using same code with Private Storage account, it is sometimes throwing reading error and sometimes it is throwing writing error on blob storage, even if SAS token has all required permissions (Read, Write, Delete, Create, List, Add etc..), and even private storage account is also having DNS configuration available. And for other use, I am able to add/update/delete blobs on the same private storage account.
Only problem I am facing is while calling ImportDevicesAsync method of IoTHub's RegistryManager.</p>
<p>My sample code is as below:
To create devices.txt file and upload it on proper container.</p>
<pre><code>for (int i = deviceIndex; i &lt; deviceCount + deviceIndex; i++)
{
    var deviceToAdd = new ExportImportDevice()
    {
        Id = $&quot;{devicePrefix}{i.ToString().PadLeft(6, '0')}&quot;,
        ImportMode = importMode == &quot;delete&quot; ? ImportMode.Delete : ImportMode.Create,
        Status = DeviceStatus.Enabled,
        Authentication = new AuthenticationMechanism()
        {
            SymmetricKey = new SymmetricKey()
            {
                PrimaryKey = CryptoKeyGenerator.GenerateKey(32),
                SecondaryKey = CryptoKeyGenerator.GenerateKey(32)
            }
        },
        Tags = new TwinCollection(initialTags.SerializeObject())
    };
    serializedDevices.Add(deviceToAdd.SerializeObject());
}

// Write the list to the blob
StringBuilder sb = new();
serializedDevices.ForEach(serializedDevice =&gt; sb.AppendLine(serializedDevice));
Uri uri = new(assetsBlockBlobUrl + &quot;?&quot; + assetsBlobContainerSas);
CloudBlockBlob blob = new(uri);
await blob.DeleteIfExistsAsync();

using (CloudBlobStream stream = await blob.OpenWriteAsync())
{
    byte[] bytes = Encoding.UTF8.GetBytes(sb.ToString());
    for (var i = 0; i &lt; bytes.Length; i += 500)
    {
        int length = Math.Min(bytes.Length - i, 500);
        await stream.WriteAsync(bytes.AsMemory(i, length));
    }
}
</code></pre>
<p>To import devices from the same container using registryManager.ImportDeviceAsync method:</p>
<pre><code>RegistryManager registryManager = RegistryManager.CreateFromConnectionString(Environment.GetEnvironmentVariable(&quot;iotHubConnectionString&quot;));
JobProperties importJob = await registryManager.ImportDevicesAsync(containerSasUri, containerSasUri);
////Wait until job is finished
while (true)
{
    importJob = await registryManager.GetJobAsync(importJob.JobId);
    _logger.LogInformation(&quot;import job &quot; + importJob.Status);
    if (importJob.Status == JobStatus.Completed)
    {
        return Common.Utils.GetObjectResult(importMode == &quot;delete&quot; ? MessageConstants.SuccessDeletedAsset : MessageConstants.SuccessCreatedAsset);
    }
    else if (importJob.Status == JobStatus.Failed)
    {
        return Common.Utils.GetObjectResult(importMode == &quot;delete&quot; ? MessageConstants.DeleteDeviceFail : MessageConstants.CreateDeviceFail);
    }
    else if (importJob.Status == JobStatus.Cancelled)
    {
        return Common.Utils.GetObjectResult(importMode == &quot;delete&quot; ? MessageConstants.DeviceDeletionCancel : MessageConstants.DeviceCreationCancel);
    }
    await Task.Delay(TimeSpan.FromSeconds(5));
}
</code></pre>
",https://stackoverflow.com/questions/75319778/unable-to-bulk-import-devices-with-private-storage-account,"['azure', 'sdk', 'azure-blob-storage', 'azure-iot-hub', 'private-network']",73,False,0,0
Pygame randomly stops responding,"<p>I'm new to developing with pygame and I ran into a problem that I can't  consistently replicate. I have a suspicion that the problems occurs somewhere in menu handling, but I can't pinpoint the problem. I ran into the problem the most times if I spammed buttons in menu (tried stress testing) and sometimes when pausing the game.</p>
<p>EDIT:</p>
<p>To clarify the problem a bit more. I strongly suspect that the problem occurs while handling menu states. The code and the game works as intended and perfectly fine for 99% of the time, but in that 1% the window freezes and stops responding. Next two scenarios are the ones that occured the most.</p>
<p>Scenario 1:
Last time I ran into the problem was when playing the game normally and then pressing ESC to enter the pause menu. Game froze and stopped responding. Expected result: Pause menu opens, without causing the game to stop responding and you can resume the game, access settings or go back to main menu from the menu (The correct scenario occurs 99% of the time).</p>
<p>Scenario 2 (happend in the past doesn't anymore):
In the past I also ran into the same problem while stress testing menus, by fast switching between them, the game also froze and stopped responding, but I later added cooldown to limit the speed and ensure everything was loaded properly and haven't had problems with this scenario ever since.</p>
<p>So the problem is game randomly freezes and stops responding and the problem is really random and I can't get to the point where I can consistantly replicate it, I can do the same thing (play the game and go to the pause menu) a thousand times and it will work fine, but then one time it will just stop responding. So the question in short is did I forgot to check for something or if i forgot to add something while handling different menus, because like i said im new to pygame and don't know how everything works. And again the problem is really hard to replicate and pinpoint what exactly happens, it usually takes me 30 min of trying to make it happen again.</p>
<p>Game loop:</p>
<pre class=""lang-py prettyprint-override""><code>while settings.RUNNING:

    settings.EVENTS = pygame.event.get()
    
    if (settings.MUSIC_MUTED):
        pygame.mixer.music.set_volume(0)
    else:
        pygame.mixer.music.set_volume(int(settings.MUSIC_VOLUME) / 100)


    if not (settings.GAME_PAUSED):

        for event in settings.EVENTS:
            if event.type == pygame.QUIT:
                settings.RUNNING = False
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    settings.MENU_STATE = 'pause'
                    pause_start = pygame.time.get_ticks()
                    settings.MENU_CD = pygame.time.get_ticks()
                    settings.GAME_PAUSED = True

        if settings.FINISHED:
            settings.FINISHED = False
            level = Level(settings)

        pygame.mixer.music.unpause()
        level.draw()


    elif (settings.GAME_PAUSED):
      #Some other code

    pygame.display.update()
    GAME_CLOCK.tick(60)

pygame.quit()
sys.exit()
</code></pre>
<p>Pause part event handling:</p>
<pre class=""lang-py prettyprint-override""><code>for event in settings.EVENTS:
            if event.type == pygame.QUIT:
                settings.RUNNING = False
            if settings.MENU_STATE == &quot;main&quot;:
                if event.type == pygame_gui.UI_TEXT_ENTRY_CHANGED and event.ui_object_id == &quot;#name_input_field&quot; and (pygame.time.get_ticks() - settings.MENU_CD) &gt;= 175:
                    settings.PLAYER_NAME = event.text
                NAME_INPUT.process_events(event)
            if settings.MENU_STATE == &quot;keybinds&quot; and waiting_input:
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        if waiting_for == &quot;left&quot;:
                            left_button.image = settings.MENU_ASSETS[&quot;buttons&quot;][&quot;button&quot;]
                        if waiting_for == &quot;right&quot;:
                            right_button.image = settings.MENU_ASSETS[&quot;buttons&quot;][&quot;button&quot;]
                        if waiting_for == &quot;jump&quot;:
                            jump_button.image = settings.MENU_ASSETS[&quot;buttons&quot;][&quot;button&quot;]
                        waiting_for = &quot;&quot;
                        waiting_input = False
                    elif event.key not in [settings.KEYBINDS['left'], settings.KEYBINDS['right'], settings.KEYBINDS['jump']]:
                        if waiting_for == &quot;left&quot;:
                            save_settings({
                                'left' : event.key,
                                'right': settings.KEYBINDS['right'],
                                'jump': settings.KEYBINDS['jump']
                            })
                            left_button.image = settings.MENU_ASSETS[&quot;buttons&quot;][&quot;button&quot;]
                        elif waiting_for == &quot;right&quot;:
                            save_settings({
                                'left' : settings.KEYBINDS['left'],
                                'right': event.key,
                                'jump': settings.KEYBINDS['jump']
                            })
                            right_button.image = settings.MENU_ASSETS[&quot;buttons&quot;][&quot;button&quot;]
                        elif waiting_for == &quot;jump&quot;:
                            save_settings({
                                'left' : settings.KEYBINDS['left'],
                                'right': settings.KEYBINDS['right'],
                                'jump': event.key
                            })
                            jump_button.image = settings.MENU_ASSETS[&quot;buttons&quot;][&quot;button&quot;]

                        set_keybinds(settings)
                        waiting_input = False
                        waiting_for = &quot;&quot;
</code></pre>
<p>One of the menus (the one where the problem occured latest):</p>
<pre class=""lang-py prettyprint-override""><code>        if (settings.MENU_STATE == 'pause'):
            print(&quot;pause menu&quot;, settings.GAME_PAUSED, settings.RUNNING)
            pygame.mixer.music.pause()
            title_image = pygame.image.load('./assets/menu/title/title.png').convert_alpha()
            SCREEN.blit(title_image, ((settings.SCREEN_WIDTH/2 - title_image.get_width()/2),(settings.SCREEN_HEIGHT/4 - title_image.get_height() * 3 / 4)))

            if resume_button.draw(SCREEN) and (pygame.time.get_ticks() - settings.MENU_CD) &gt;= 175:
                settings.GAME_PAUSED = False
                level.pause_time += (pygame.time.get_ticks() - pause_start)
                pause_start = 0
                continue

            if settings_button.draw(SCREEN) and (pygame.time.get_ticks() - settings.MENU_CD) &gt;= 175:
                settings.PREVIOUS_MENU = &quot;pause&quot;
                settings.MENU_STATE = &quot;settings&quot;
                settings.MENU_CD = pygame.time.get_ticks()
                continue

            if mainmenu_button.draw(SCREEN) and (pygame.time.get_ticks() - settings.MENU_CD) &gt;= 175:
                settings.MENU_STATE = &quot;main&quot;
                settings.MENU_CD = pygame.time.get_ticks()
                continue
</code></pre>
<p>Additional info if needed:
My python version is 3.9.13.
For any additional code references, that you think you might need, the whole code is available on: <a href=""https://github.com/AnzeSavli/Pustolovko"" rel=""nofollow noreferrer"">github link</a></p>
",https://stackoverflow.com/questions/74998841/pygame-randomly-stops-responding,"['python', 'pygame']",58,False,-1,1
Android app crashing after 3 rotations. JAVA/ANDROID,"<p>Im not sure what i could have done to make it consistently crash after 3 rotations. I was debugging and profiling the app while testing the crash and not once did the debug console tell me anything like a null pointer or something, it crashes silently. The app is also not using any resources and does not use more after a rotation so i couldn't see a memory leak being the problem. I have java experience from developing minecraft plugins and mods but im new and unfamiliar with the android enviroment. The only thing i could think of is during the lifecycle events of a fragment, I recently added methods for onStop,onPause,OnStart, and OnDestroy to kill and restart a runnable i have that updates the data on the screen by the second, to not use as much resources when inactive. Its odd as its consistently 3 rotations, What is the relevence of 3 i wonder?</p>
<p>It didn't crash after any amount of rotations prior to this, I had done rotation stress testing to look for leaks and it never crashed. I've added quite a lot of code since ive last known it didn't crash, Im kinda lost on where to start, being so new to the enviroment.</p>
",https://stackoverflow.com/questions/75903855/android-app-crashing-after-3-rotations-java-android,"['android', 'android-activity', 'android-lifecycle']",26,False,0,0
Nestjs Issue with Healthchecks,"<p>We are running into some healthcheck issues with Nestjs and TypeORM.
Whenever we start stress testing an ECS Cluster, the health checks start failing randomly and signal the ECS to start draining the unhealthy tasks. This triggers the traffic to move on to the remaining container instances which start failing over time and because it takes longer for containers to stand up than shut down, we are left with the API coming down to a grinding halt. We start observing Gateway Timeouts on ECS after a while.</p>
<p>What's interesting is that the database is still up and running. It just doesn't respond to the healthchecks within a second (i'm guessing?) and saturates the healthchecks. The DB is accessible and performant when we query it from PGSQL admins so we know that it's not the db. It's just that the healthchecks are unable to function as expected.</p>
<p>Here is what our current healthcheck code looks like:</p>
<pre><code>    const result = await this.health.check([
      () =&gt; this.typeorm.pingCheck('database'),
      //() =&gt; this.memory.checkHeap('memory_heap', 4000 * 1024 * 1024),
      //() =&gt; this.memory.checkRSS('memory_rss', 4000 * 1024 * 1024),
    ]);
    
    if (result.status !== 'ok') {
      this.logger.error('API is down');
    }
    
    if (result.info.database.status !== 'up') {
      this.logger.error('DB is down');
    }
</code></pre>
<p>As you can see, there isn't much to it. We have removed the memory heap and memory checks to see if they have an impact on the DB checks.</p>
<p>Most of the times some healthchecks report DB UP, while others report DB down:</p>
<pre><code>&quot;:&quot;ok&quot;,&quot;info&quot;:{&quot;database&quot;:{&quot;status&quot;:&quot;up&quot;},&quot;memory_heap&quot;:{&quot;status&quot;:&quot;up&quot;},&quot;memory_rss&quot;:{&quot;status&quot;:&quot;up&quot;}},&quot;error&quot;:{},&quot;details&quot;:{&quot;database&quot;:{&quot;status&quot;:&quot;up&quot;},&quot;memory_heap&quot;:{&quot;status&quot;:&quot;up&quot;},&quot;memory_rss&quot;:{&quot;status&quot;:&quot;up&quot;}}}
</code></pre>
<p>This has brought our APIs to a grinding halt. Does anyone have any ideas on how to resolve this? We would highly appreciate it.</p>
",https://stackoverflow.com/questions/75706381/nestjs-issue-with-healthchecks,['nestjs'],59,False,0,0
Threads calling the same code resulting in deadlock [Mysql],"<p><strong>Background:</strong></p>
<p>I have a stock market website, therefore consistency is extremely important to me. To accommodate this, I tend to utilize the most strict isolation level SERIALIZABLE.</p>
<p>Initial testing worked fine, but stress testing my back-end code with threads has revealed a nasty dead-lock.</p>
<p><strong>Problem</strong>:</p>
<p>Ive isolated the problem to the api endpoint /open. This endpoint calls many functions that need to execute under a transaction. I will put the code below but here is a high-level of what locks are being acquired</p>
<ul>
<li>getBuyingPower - Lock User ROW and get their buying power</li>
<li>await Users.update - Update User ROW with decreased buying power</li>
<li>createLedgerEntry - Inserts entry into LEDGER table</li>
<li>createStockOwner - Inserts entry into StockOwners table AND updates  payout and pot size columns for universe TABLE</li>
</ul>
<p><em><strong>createStockOwner</strong></em> As little as it seems that I understand how locks work, I have to guess this is where the issue is.
As this function updates the payout and pot size for a given universe</p>
<p>This table looks like
universeId, universeName, potSize, payout</p>
<p>All the threads are different users, but they are all in the same universe, meaning every thread is trying to update the SAME row.</p>
<p>Now my belief was that since I acquire the locks in the same order on every thread (there are running the same code), that the serializable lock would simply wait for the one before it to finish before updating the row. I dont know why they would wait on each other.</p>
<p><strong>What Ive tried:</strong></p>
<p>I implemented a retry middleware, in which if a transaction fails due to deadlock to retry a max of 3 times. This did not solve the problem.</p>
<p>I know that debugging deadlocks can be tough, so I dont expect an answer to be given here, but please send me tips on how to debug this, and correct me where I am wrong about how the Serializable lock works.</p>
<p><strong>Code:</strong></p>
<pre><code>router.post('/open', async (req, res) =&gt; {
const transaction = await sequelize.transaction({ isolationLevel: Sequelize.Transaction.ISOLATION_LEVELS.SERIALIZABLE });
try {
    const { token, universeId } = req.body;
    const userId = extractUserFromToken(token);
    const buyingPower = await getBuyingPower(userId, transaction);

    if (buyingPower &lt; 1) {
        throw new Error('Not enough buying power');
    }

    await Users.update({ balance: buyingPower - 1 }, { where: { id: userId }, transaction: transaction });
    const ledgerEntry = await createLedgerEntry({
        userId,
        type: 'purchase',
        amount: 1,
    }, transaction)
    const universe = await getUniverse([universeId]);
    if (universe.length === 0) {
        throw new Error('Universe does not exist');
    }

    const stocks = await getAllStockCountInUniverse(universeId);
    const randomStock = await chooseRandomStock(stocks);
    const stock = await getStockById(randomStock.stockId)

    await createStockOwner({
        ledgerid: ledgerEntry.id,
        stockuuid: uuidv4(),
        stockId: stock.id,
        currentOwner: userId,
        universeId: universeId,
    }, transaction)

    await transaction.commit();

    res.json({ stock });
} catch (error) {
    await transaction.rollback();
    console.error(error);
    res.status(500).json({ error: error.message });
}
});
</code></pre>
<p>ERROR:</p>
<pre><code>Unable to update pot size: Deadlock found when trying to get lock; try restarting transaction
</code></pre>
<p>Code in Question:</p>
<pre><code>const createStockOwner = async (stockOwnerData, transaction) =&gt; {
try {
    const stockOwner = await StockOwners.create(stockOwnerData, { transaction });
    await updatePotSize(stockOwnerData.universeId, transaction)
    await updatePayout(stockOwnerData.universeId, 1, transaction);
    return stockOwner;
} catch (error) {
    console.error(error);
    throw new Error('Could not create stock owner');
}
};


const updatePotSize = async (universeId, transaction) =&gt; {
try {
    const universe = await Universes.findOne({
        where: {
            id: universeId
        }, transaction
    });
    const potSize = universe.potSize;
    await universe.update({
        potSize: potSize + 1
    }, { transaction });
} catch (error) {
    console.error('Unable to update pot size:', error.message);
}
}

  const updatePayout = async (universeId, amount, transaction) =&gt; {
try {
    if (isNaN(amount) || amount === null) {
        throw new Error('Invalid amount value');
    }

    const universe = await Universes.findOne({
        where: {
            id: universeId
        }, transaction
    });

    if (!universe) {
        throw new Error('Universe not found');
    }
    let payout = universe.payout;

    if (isNaN(payout) || payout === null) {
        payout = 0;
    }

    const newPayout = new Big(payout).plus(new Big(amount));
    await universe.update({ payout: newPayout.toFixed(2) }, { transaction });

    return newPayout;
} catch (error) {
    console.error('Unable to get payout:', error);
    throw error;
}
}
</code></pre>
",https://stackoverflow.com/questions/76097658/threads-calling-the-same-code-resulting-in-deadlock-mysql,"['mysql', 'node.js', 'multithreading', 'deadlock']",35,True,-1,1
Losing Available Physical Memory when repeatedly starting and closing DirectX 11 applications,"<p>We run our kiosk system on a 64-bit Windows 10 system with 8 GB of memory and no swap file.  We recently started changing approaches and building and executing smaller individual DirectX 11 executables which open and close repeatedly rather than one large executable that just runs once. After stress-testing by rapidly opening and closing the small executables for several weeks, they started failing to open due to memory allocation failures. We then found that as they open and close, the amount of “available physical memory”, as returned by the GlobalMemoryStatusEx function, is constantly shrinking. I certainly can see how an application could leak memory while it is running, but what seems unusual about this is that this memory is not recovered after the executables exit.</p>
<p>So of course, my questions are whether anyone else seen this behavior and if so, what was wrong and how can it be fixed or at least mitigated?</p>
<p>I’ve tried some variations in order to isolate the problem, and I can go into more detail on these if necessary. I can say that the memory allocation failures start once I reach about 2 GB of available physical memory when running with the Nvidia card we use, and when running on the motherboard’s onboard Intel video the system can run until the memory drops much lower. It seems noteworthy that  that this leak occurs with both Nvidia and Intel video.</p>
<p>I have attempted to see where the memory is going but I’m still learning how to track this. I use SysInternal’s RamMap application to “Empty” the various Working Sets and Lists before and after the tests to see how much memory is truly locked up and unavailable.</p>
<p>During one of my test runs, I did see a large amount of the physical memory that appeared to be lost (about 650 MB)  suddenly recover. I have only seen that once though. This made me wonder if whatever was occupying this memory was supposed to get cleaned up in the background (not immediately released as soon as the application closed) but that this mechanism was getting broken or held up nearly all the time.</p>
",https://stackoverflow.com/questions/75861392/losing-available-physical-memory-when-repeatedly-starting-and-closing-directx-11,['directx-11'],27,False,0,0
