Question

I use JMeter to test my web application. and my test case is to add a record in database. and then I set the "number of thread user" to 20, it means that it will simulate 20 users work at the same time. and then I run the test case. But finally i found the system didn't create 20 records in database, but instead just create 13 records in database.

I want to know why this happened ? Is it possible that because in my web application i didn't add a "synchronized" in front of the add records method ? I used linq, If two user post a request to create a record to server at the same time, what will happen? Just create a record or can successfully create two records, or unknown ?

Following is the sample code for create a record in database:

       public int SaveEventGroup(int id, Models.Entities.EventGroup e, Nullable<int> setpublish)
    {
        try
        {
            Entities.EventGroup db;
            if (id == 0)
            {
                db = new Entities.EventGroup();
                db.CreatedBy = e.CreatedBy;
                db.CreateDatetime = DateTime.Now;
                db.Status = true;
            }
            else
            {
                db = this.GetEventGroup(id);
            }

            db.NameCN = e.NameCN;
            db.NameEN = e.NameEN;
            db.NameZH = e.NameZH;
            db.NamePT = e.NamePT;
            db.DisplayOrder = GetGroupMaxDisplayOrder() + 1;

            if (setpublish == null)
            {
                db.PublishStatus = false;
                db.PublishDatetime = null;
                db.UpdateDatetime = DateTime.Now;
                db.UpdatedBy = e.UpdatedBy;
            }

            if (id == 0)
                dataContext.AddToEventGroupSet(db);

            dataContext.SaveChanges();

            return db.Id;
        }
        catch (Exception ex)
        {
            log.Error(ex.Message, ex);
            throw ex;
        }
    }
Was it helpful?

Solution

the database itself should be ACID compliant, so i doubt the issue is with the database when it comes to synchronization. if you insert a new record and that record is keyed by something like an auto-incrementing integer, the database isn't going to stomp on that unless you tell it to update by that id, rather than insert a new record. but since you are not writing the SQL, who really knows what you are instructing the database to do.

i'd suggest removing linq from the equation, and manually writing this up. what you are testing appears to be a very simple "upsert" operation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top