{"action":"created","issue":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/3956","repository_url":"https://api.github.com/repos/Automattic/mongoose","labels_url":"https://api.github.com/repos/Automattic/mongoose/issues/3956/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/mongoose/issues/3956/comments","events_url":"https://api.github.com/repos/Automattic/mongoose/issues/3956/events","html_url":"https://github.com/Automattic/mongoose/issues/3956","id":139190439,"number":3956,"title":"Stress test problem","user":{"login":"leopoldfreeman","id":8280387,"avatar_url":"https://avatars.githubusercontent.com/u/8280387?v=3","gravatar_id":"","url":"https://api.github.com/users/leopoldfreeman","html_url":"https://github.com/leopoldfreeman","followers_url":"https://api.github.com/users/leopoldfreeman/followers","following_url":"https://api.github.com/users/leopoldfreeman/following{/other_user}","gists_url":"https://api.github.com/users/leopoldfreeman/gists{/gist_id}","starred_url":"https://api.github.com/users/leopoldfreeman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leopoldfreeman/subscriptions","organizations_url":"https://api.github.com/users/leopoldfreeman/orgs","repos_url":"https://api.github.com/users/leopoldfreeman/repos","events_url":"https://api.github.com/users/leopoldfreeman/events{/privacy}","received_events_url":"https://api.github.com/users/leopoldfreeman/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Automattic/mongoose/labels/needs%20clarification","name":"needs clarification","color":"EB219B"}],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/Automattic/mongoose/milestones/100","html_url":"https://github.com/Automattic/mongoose/milestones/4.4.13","labels_url":"https://api.github.com/repos/Automattic/mongoose/milestones/100/labels","id":1689465,"number":100,"title":"4.4.13","description":"","creator":{"login":"vkarpov15","id":1620265,"avatar_url":"https://avatars.githubusercontent.com/u/1620265?v=3","gravatar_id":"","url":"https://api.github.com/users/vkarpov15","html_url":"https://github.com/vkarpov15","followers_url":"https://api.github.com/users/vkarpov15/followers","following_url":"https://api.github.com/users/vkarpov15/following{/other_user}","gists_url":"https://api.github.com/users/vkarpov15/gists{/gist_id}","starred_url":"https://api.github.com/users/vkarpov15/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vkarpov15/subscriptions","organizations_url":"https://api.github.com/users/vkarpov15/orgs","repos_url":"https://api.github.com/users/vkarpov15/repos","events_url":"https://api.github.com/users/vkarpov15/events{/privacy}","received_events_url":"https://api.github.com/users/vkarpov15/received_events","type":"User","site_admin":false},"open_issues":13,"closed_issues":8,"state":"open","created_at":"2016-04-07T13:55:28Z","updated_at":"2016-04-20T05:34:42Z","due_on":"2016-04-17T07:00:00Z","closed_at":null},"comments":18,"created_at":"2016-03-08T06:17:28Z","updated_at":"2016-04-20T05:34:42Z","closed_at":"2016-04-20T05:34:42Z","body":"I find a problem when I test the proformance of our game server. Our schema:\r\n\r\n```javascript\r\nvar playerSchema = new Schema({\r\n    uid: {\r\n        type: String,\r\n        required: true\r\n    },\r\n    data: {\r\n        //...\r\n    },\r\n    dataRev: {\r\n        type: Number,\r\n        required: true\r\n        default: 0\r\n    }\r\n}, {\r\n    //...\r\n});\r\n```\r\n\r\nTo prevent overwriting the data field, we use dataRev to protect it:\r\n```javascript\r\nfunction testWrite(player, cb) {\r\n    PlayerModel.findOneAndUpdate(\r\n        {uid: player.uid, dataRev: player.dataRev}, \r\n        {$inc: {dataRev: 1}, $set: {data: player.data}}, \r\n        {upsert: false, select: {dataRev: 1}}, \r\n        function(err, doc) {\r\n            if (doc) {\r\n                player.dataRev = doc.dataRev;\r\n            }\r\n            //...\r\n        }\r\n    );\r\n}\r\n```\r\n\r\nThe test routine will try to use the up function to update the data field which size is about 1KB.\r\n\r\nThe stress test program will create 4 threads and each thread will create 500 clients. Then each client will call the API of the server side to init the doc in database. After that, it will call the test routine every 10 seconds for 5 times.\r\n\r\nThe result shows the findOneAndUpdate could not find a few docs at the 2nd time (about 5%, I checked the player.dataRev, it is currect.). The 1st, 3rd, 4th and 5th were all passed. If I remove the dataRev from the query condition, there will be no failure. So, it cannot find the dataRev! In other words, there must be something wrong with $inc.\r\n\r\nI ran the stress test program for several times. Everytime the failure happened at the 2nd time. <del>Please note that there are about 10 seconds between the two requests from the same client. </del>\r\n\r\nThere will be no failure if I create 4 threads and each thread only create 100 clients.\r\n\r\nMongoDB: v3.2.3\r\nMongoose: v4.4.6\r\nCentOS 7.2 amd64\r\n\r\n\r\n "},"comment":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/comments/212266763","html_url":"https://github.com/Automattic/mongoose/issues/3956#issuecomment-212266763","issue_url":"https://api.github.com/repos/Automattic/mongoose/issues/3956","id":212266763,"user":{"login":"leopoldfreeman","id":8280387,"avatar_url":"https://avatars.githubusercontent.com/u/8280387?v=3","gravatar_id":"","url":"https://api.github.com/users/leopoldfreeman","html_url":"https://github.com/leopoldfreeman","followers_url":"https://api.github.com/users/leopoldfreeman/followers","following_url":"https://api.github.com/users/leopoldfreeman/following{/other_user}","gists_url":"https://api.github.com/users/leopoldfreeman/gists{/gist_id}","starred_url":"https://api.github.com/users/leopoldfreeman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leopoldfreeman/subscriptions","organizations_url":"https://api.github.com/users/leopoldfreeman/orgs","repos_url":"https://api.github.com/users/leopoldfreeman/repos","events_url":"https://api.github.com/users/leopoldfreeman/events{/privacy}","received_events_url":"https://api.github.com/users/leopoldfreeman/received_events","type":"User","site_admin":false},"created_at":"2016-04-20T05:34:42Z","updated_at":"2016-04-20T05:34:42Z","body":"Hi, I've reimplemented some parts of the stress test program recently. After I run tests with the new program and the server doesn't complain any more. So it should be a bug in previous version of stress test program. I'll compare the codes. Sorry."}}