Sunday, 15 February 2015

php - Mongo Update Speed -



php - Mongo Update Speed -

i have script when run on local scheme runs when running on production scheme runs much slower. have confirmed php profiler slow-down happening in update method on mongocollection object. have copied php software (binary , modules) production scheme local scheme create sure isn't due difference in machine/network. running production php software on local scheme runs slow. problem not machine or network. since same script not script. points 1 of 3 possibilities:

difference in php version difference in mongo driver version difference in configuration

the script in question iterates through records in collection , makes update each one. update has write concern set 0 speed more of import knowing executed successfully. php profiler stopped providing info 1 time called update (since update implemented in c). turned next strace see if scheme calls help explain difference in speed. loop updates beingness issued has next strace output on fast system:

sendto(3, "\202\0\0\0\206\0\0\0\0\0\0\0\321\7\0\0\0\0\0\0properties_2"..., 130, msg_dontwait, null, 0) = 130 write(1, ".", 1) = 1 sendto(3, "\202\0\0\0\207\0\0\0\0\0\0\0\321\7\0\0\0\0\0\0properties_2"..., 130, msg_dontwait, null, 0) = 130 write(1, ".", 1) = 1 sendto(3, "\202\0\0\0\210\0\0\0\0\0\0\0\321\7\0\0\0\0\0\0properties_2"..., 130, msg_dontwait, null, 0) = 130 write(1, ".", 1) = 1

i outputting "." between each update have feedback indicate how fast updates going. when running same script on slower php see following:

sendto(3, "\357\0\0\0v\0\0\0\0\0\0\0\324\7\0\0\0\0\0\0properties_2"..., 239, msg_dontwait, null, 0) = 239 poll([{fd=3, events=pollin|pollerr|pollhup}], 1, 30000) = 1 ([{fd=3, revents=pollin}]) recvfrom(3, "1\0\0\0009\0.\nv\0\0\0\1\0\0\0\10\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 8192, msg_dontwait, null, null) = 49 write(1, ".", 1) = 1 sendto(3, "\357\0\0\0w\0\0\0\0\0\0\0\324\7\0\0\0\0\0\0properties_2"..., 239, msg_dontwait, null, 0) = 239 poll([{fd=3, events=pollin|pollerr|pollhup}], 1, 30000) = 1 ([{fd=3, revents=pollin}]) recvfrom(3, "1\0\0\0\201\0.\nw\0\0\0\1\0\0\0\10\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 8192, msg_dontwait, null, null) = 49 write(1, ".", 1) = 1 sendto(3, "\357\0\0\0x\0\0\0\0\0\0\0\324\7\0\0\0\0\0\0properties_2"..., 239, msg_dontwait, null, 0) = 239 poll([{fd=3, events=pollin|pollerr|pollhup}], 1, 30000) = 1 ([{fd=3, revents=pollin}]) recvfrom(3, "1\0\0\0\320\0.\nx\0\0\0\1\0\0\0\10\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 8192, msg_dontwait, null, null) = 49 write(1, ".", 1) = 1 sendto(3, "\357\0\0\0y\0\0\0\0\0\0\0\324\7\0\0\0\0\0\0properties_2"..., 239, msg_dontwait, null, 0) = 239 poll([{fd=3, events=pollin|pollerr|pollhup}], 1, 30000) = 1 ([{fd=3, revents=pollin}]) recvfrom(3, "1\0\0\0\365\0.\ny\0\0\0\1\0\0\0\10\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 8192, msg_dontwait, null, null) = 49 write(1, ".", 1) = 1

notice have added scheme calls. looks checking reply me indicates it's not using write concern 0. major difference between 2 php installations fast 1 using driver 1.4.5 while slow 1 using 1.5.3.

i compared update code both versions. in 1.4.5 it seems send message , return. on other hand looking @ 1.5.3 it sends message gets reply. don't see skipping checking reply if write status 0. if follow code extracts reply can see calls these 2 additional scheme calls.

can understand improve help me figure out how code running fast in production. on fast php install (mongo driver 1.4.5) script executes in 2-3 minutes. on slow scheme (mongo driver 1.5.3) killed after 30 minutes because tired of waiting. knows how long have taken done.

(note: updated original reply after research)

the new write operation commands came in 2.6 , hence in utilize between supported driver (php 1.5+) , mongodb server (2.6+) mean new semantics of w=0 writes in play. means server waits operation finish before sending response (that is, difference between w=0 , w=1 w=0 omits error details). driver still waits response before returning phone call (i.e. no longer fire , forget).

you can see in mongodb shell also, , official way around utilize new bulk api. although know 1.5 driver fall legacy write operations when connecting 2.4 , below server, there no way forcefulness behavior in php driver.

php performance mongodb

No comments:

Post a Comment