English 中文(简体)
Why didn t see 10 records in database?
原标题:

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;
        }
    }
最佳回答

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.

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签