mirc treebar script firing off a set invaild parameters randomly - mirc

Below is the script I use for my treebar in my mirc client it fires of in the status window */set:invalid parameters not sure which set it is and most fixes I've tried including check for mismatched () or [] just cause other errors. Any help finding where the invalid parameters are would be appreciated.
;--[Startup event]
on *:START: { startsektor }
;--[Aliases]--
alias startsektor { switch }
;--[switchbar]
alias switch {
if ($dialog(switchbar)) { dialog -x switchbar }
dialog -m switchbar switchbar
}
dialog switchbar {
title "switchbar"
size -1 -1 135 445
option pixels
}
on *:dialog:switchbar:init:*: {
dcx Mark $dname DCX_Switch
xdialog -q $dname +r cross
xdialog -c $dname 1 treeview 0 0 135 839 showsel hasbuttons haslines
xdid -i $dname 1 +b $color(1)
xdid -i $dname 1 +l $color(0)
xdid -f $dname 1 +ab ansi 8 ariel
.timer 1 0 xdock -m $dialog($dname).hwnd +l
.timer 1 0 iSwitch
}
alias -l xSwitch {
if (%New. [ $+ [ $+($scon($1),$active) ] ] == On) { xdid -j switchbar 1 $xdid(switchbar,1,$+($chr(9),$2,$chr(9)),$1).find -1 7 }
else { xdid -v switchbar 1 $xdid(switchbar,1,$+($chr(9),$2,$chr(9)),$1).find $chr(9) $2 }
}
alias -l eSwitch {
if ($scon($1).server) { xdid -v switchbar 1 $xdid(switchbar,1,$+($chr(9),*,$chr(9)),W,$calc($1 + 1)).find $chr(9) $scon($1).server }
elseif (!$scon($1).server) { xdid -v switchbar 1 $xdid(switchbar,1,$+($chr(9),*,$chr(9)),W,$calc($1 + 1)).find $chr(9) (Not Connected) }
}
alias iSwitch {
xdid -r switchbar 1
xdid -w switchbar 1 +n 0 icons/10.ico
xdid -w switchbar 1 +n 0 icons/22.ico
xdid -w switchbar 1 +n 0 icons/adminprotection.ico
xdid -w switchbar 1 +n 0 icons/userlist2.ico
xdid -w switchbar 1 +n 0 icons/star.ico
xdid -w switchbar 1 +n 0 icons/10.ico
xdid -w switchbar 1 +n 0 icons/star.ico
var %scid = 1
while (%scid <= $scon(0)) {
scon %scid
if (!$server) { xdid -a switchbar 1 %scid $chr(9) +ceb 3 3 0 0 0 $color(0) $color(0) [Not Connected] $chr(9) This server is NOT connected. }
elseif ($server) { xdid -a switchbar 1 %scid $chr(9) +ceb 2 2 0 0 0 $color(0) $color(0) $server $chr(9) Server - $server $chr(124) Connected at - $time(ddd hh:nn:ss tt)
xdid -a switchbar 1 %scid 1 $chr(9) +ce 1 1 0 0 0 $color(0) $color(0) Channels ( $+ $chan(0) $+ )
var %c = 1
while (%c <= $chan(0)) {
xdid -a switchbar 1 %scid 1 -1 $chr(9) +ce $iif(%New. [ $+ [ $+($server,$chan(%c)) ] ],6 6,5 5) 0 0 0 $color(0) $color(0) $iif(%New. [ $+ [ $+($server,$chan(%c)) ] ] == On,$+($chr(40),$chan(%c),$chr(41)),$chan(%c)) $chr(9) $chan(%c) - $iif(%New. [ $+ [ $+($server,$chan(%c)) ] ] == On,New Message,No new messages)
inc %c
}
xdid -a switchbar 1 %scid 2 $chr(9) +ce 4 4 0 0 0 $color(0) $color(0) Query ( $+ $query(0) $+ )
var %q = 1
while (%q <= $query(0)) {
xdid -a switchbar 1 %scid 2 -1 $chr(9) +ce $iif(%New. [ $+ [ $+($server,$query(%q)) ] ],4 4,1 1) 0 0 0 $color(0) $color(0) $iif(%New. [ $+ [ $+($server,$query(%q)) ] ] == On,$+($chr(40),$query(%q),$chr(41)),$query(%q)) $chr(9) $query(%q) - $iif(%New. [ $+ [ $+($server,$query(%q)) ] ] == On,New Message,No new messages)
inc %q
}
}
inc %scid
}
xdid -a switchbar 1 %scid 3 $chr(9) +ceb 5 5 0 0 0 $color(0) $color(0) Windows ( $+ $window(0) $+ )
var %win = $window(0)
var %w = 1
while (%w <= %win) {
xdid -a switchbar 1 %scid 3 -1 $chr(9) +ce 5 5 0 0 0 $color(0) $color(0) $window(%w)
inc %w
}
}
on *:ACTIVE:*: { set %New. [ $+ [ $+($server,$active) ] ] Off | iSwitch }
on *:TEXT:*:#: {
if ($active == $chan) { halt }
elseif (%New. [ $+ [ $+($server,$chan) ] ] !== On) { set %New. [ $+ [ $+($server,$chan) ] ] On | iSwitch }
}
on *:TEXT:*:?: {
if ($active == $nick) { halt }
elseif (%New. [ $+ [ $+($server,$nick) ] ] !== On) { set %New. [ $+ [ $+($server,$nick) ] ] On | iSwitch }
}
on *:ACTION:*:#: {
if ($active == $chan) { halt }
elseif (%New. [ $+ [ $+($server,$chan) ] ] !== On) { set %New. [ $+ [ $+($server,$chan) ] ] On | iSwitch }
}
on *:ACTION:*:?: {
if ($active == $nick) { halt }
elseif (%New. [ $+ [ $+($server,$nick) ] ] !== Yes) { set %New. [ $+ [ $+($server,$nick) ] ] On | iSwitch }
}
on *:CONNECT: { iSwitch }
on *:DISCONNECT: { iSwitch }
on *:RAWMODE: {
if ($active == $chan) { halt }
elseif (%New. [ $+ [ $+($server,$chan) ] ] !== On) { set %New [ $+ [ $+($server,$chan) ] ] On | -Switch }
}
on *:OPEN:?: { set %New. [ $+ [ $+($server,$nick) ] ] On | iSwitch }
on *:OPEN:#: { set %New. [ $+ [ $+($server,$chan) ] ] On | iSwitch }
alias DCX_switch {
if ($2 = mouse) { halt }
var %command = $2
tokenize 32 $4-
if (%command = sclick) {
set %target $remove($xdid(switchbar,1).seltext,$chr(40),$chr(41))
if (#* iswm %target) { window -a $window($2) | halt }
If (~* iswm %target) { window -a %target }
scon $1
if ($2 == 1) && (!$3) { list }
elseif (#* iswm %target) { window -a %target }
elseif ($query($3)) { window -a $query($3) }
elseif (!$2) { window -a "Status Window" }
}
}

The error appears when ACTIVE is being fired.
on *:ACTIVE:*: { set %New. [ $+ [ $+($server,$active) ] ] Off | iSwitch }
This happens because $active is set with a space when the focused window is the Status Window.
Which results: %New.IRC.FoobarServer.comStatus Window Off
A possible fix could replace the space with underscore(_)
set %New. [ $+ [ $+($server,$replace($active, $chr(32), _)) ] ] Off

Related

MongoDB bucket boundaries

How to use MongoDB aggregation to use $bucket to get the output for the below records
Name
value
N1
0
N2
20
N3
0.01
N4
50
N5
10
N6
20
N7
0
N8
11
N9
35
N10
51
Boundaries for this should be on 'value' column:
' =0
' >0 and <=10
' >10 and <=20
' >20 and <= 30
' >30
Note - value 0.01 should be in the range '>0 and <=10'
Pls refer to https://mongoplayground.net/p/V9mjIw1HmYK
db.collection.aggregate([
{
$bucket: {
groupBy: "$N",
// Field to group by
boundaries: [
0,
1,
10.1,
20.1,
30.1,
1000
],
// Boundaries for the buckets
default: "Other",
// Bucket id for documents which do not fall into a bucket
output: {
// Output for each bucket
"count": {
$sum: 1
},
"data": {
$push: {
"N": "$N"
}
}
}
}
},
])

In Red, how do I search through a block for a string matching a pattern?

Given:
player-wins: [
"rock breaks scissors"
"paper covers rock"
"scissors cut paper"
]
I want a function which accepts two strings, each representing any of rock, paper or scissors and then returns the element that matches, ignoring the verb.
Example:
does-player-win "paper" "rock" should return "paper covers rock" by searching the block.
UPDATE I tried to change the structure to make it easy for find or select but apparently my structure is illegal:
player-wins: [
["rock" "scissors"] "breaks"
["paper" "rock"] "covers"
["scissors" "paper"] "cut"
]
I almost forgot the most simple solution
player-wins: [
"rock" "breaks" "scissors"
"paper" "covers"" rock"
"scissors" "cuts" "paper"
]
game: func [player1 player2] [
foreach [subject predicate object] player-wins [
all [
player1 = subject
player2 = object
return reduce [player1 predicate player2]
]
]
]
>> print game "rock" "scissors"
rock breaks scissors
>> print game "scissors" "paper"
scissors cut paper
But also your second structure fits
player-wins: [
["rock" "scissors"] "breaks"
["paper" "rock"] "covers"
["scissors" "paper"] "cut"
]
win: function [player1 player2] [
game: reduce [player1 player2]
winning: player-wins/(game)
print [player1 winning player2]
]
>> win "paper" "rock"
paper covers rock
or short
win: func [player1 player2] [
print [player1 select/only player-wins reduce [player1 player2] player2]
]
And an optimized version independent of the order covering all variations could be like this
player-wins: [
"rock" "breaks"
"scissors" "cuts"
"paper" "covers"
"rock" "is covered by"
"paper" "is cut by"
"scissors" "will be broken by" "rock"
]
game: func [player1 player2] [
parse player-wins [
collect [some [keep [player1 skip player2] | 2 skip] ]
]
]
>> print game "scissors" "rock"
scissors will be broken by rock
>> print game "rock" "scissors"
rock breaks scissors

Make square bracket not appear on a new line?

I am currently working with a .txt file containing data points of certain files.
Since the files are pretty big, are they been processed in smaller parts, but the output extracted from the processing process is not sorted in any order..
They are stored as such:
1_1_0_1_0_1_1_0_232 [
0 -19.72058 -18.89882 ]
1_0_0_0_0_0_0_0_0 [
-0.5940279 -1.949468 -1.185638 ]
1_0_1_1_0_1_1_1_100 [
-5.645662 -0.005585805 -6.196068 ]
1_0_1_1_0_1_1_1_101 [
-15.86037 -1.192093e-07 -18.77053 ]
1_0_1_1_0_1_1_1_102 [
-0.5648238 -1.970869 -1.230303 ]
1_0_1_1_1_0_1_0_103 [
-0.5750521 -1.946886 -1.222114 ]
1_0_1_1_1_0_1_0_104 [
-0.5926428 -1.941596 -1.191844 ]
1_0_1_1_1_0_1_0_105 [
-25.25665 0 -31.0921 ]
1_0_1_1_1_0_1_0_106 [
-0.001282441 -6.852591 -8.399776 ]
1_0_1_1_1_0_1_0_107 [
-0.0001649993 -8.857877 -10.69688 ]
1_0_1_1_1_0_1_0_108 [
-21.66693 0 -26.18516 ]
1_0_1_1_1_0_1_0_109 [
-5.444038 -0.004555213 -8.408965 ]
1_1_0_1_0_1_0_0_200 [
-4.023561 -0.01851013 -7.704897 ]
1_1_0_1_0_1_0_0_201 [
-0.443548 -3.057277 -1.167226 ]
1_1_0_1_0_1_0_0_202 [
-0.0001185011 -9.042104 -15.60585 ]
1_1_0_1_0_1_0_0_203 [
-5.960466e-07 -14.37778 -25.2224 ]
1_1_0_1_0_1_0_0_204 [
-0.5770675 -1.951139 -1.21623 ]
1_1_0_0_1_0_1_1_205 [
-0.5849463 -1.938798 -1.207353 ]
1_1_0_0_1_0_1_1_206 [
-0.5785673 -1.949474 -1.214192 ]
1_1_0_0_1_0_1_1_207 [
-27.21529 0 -32.21676 ]
1_1_0_0_1_0_1_1_208 [
-8.75938 -0.0001605878 -12.53627 ]
1_1_0_0_1_0_1_1_209 [
-1.281936 -0.3837854 -3.188763 ]
1_0_0_0_0_0_0_1_20 [
-0.2104172 -4.638866 -1.714325 ]
1_1_1_0_0_1_1_1_310 [
-11.71479 -9.298368e-06 -13.70222 ]
1_1_1_0_0_1_1_1_311 [
-24.71166 0 -30.45412 ]
1_1_1_0_0_1_1_1_312 [
-2.145031 -0.1357486 -4.617914 ]
1_1_1_0_0_1_1_1_313 [
-5.943637 -0.003112446 -7.630904 ]
1_1_1_0_0_1_1_1_314 [
0 -25.82314 -31.98673 ]
1_1_1_0_0_1_1_1_315 [
-8.178092e-05 -13.60563 -9.426649 ]
1_1_1_0_0_1_1_1_316 [
-0.00326875 -6.071715 -6.952539 ]
1_1_1_0_0_1_1_1_317 [
-17.92782 0 -24.64391 ]
1_1_1_0_0_1_1_1_318 [
-2.979753 -0.05447901 -6.11194 ]
1_1_1_0_0_1_1_1_319 [
-0.7661145 -1.118131 -1.568804 ]
1_0_0_0_0_0_0_1_31 [
-0.5749408 -1.961912 -1.215127 ]
1_0_0_0_0_0_0_0_10 [
-4.64927e-05 -9.977531 -20.60117 ]
1_0_1_1_1_1_0_1_120 [
-0.4925551 -1.135103 -2.694917 ]
1_0_1_1_1_1_0_1_131 [
-0.6127387 -1.958336 -1.148721 ]
1_1_0_0_0_0_0_1_142 [
-0.008494892 -6.882521 -4.901772 ]
1_1_0_0_0_1_1_1_153 [
0 -20.48085 -27.38916 ]
1_1_0_0_1_0_1_0_164 [
-0.5370184 -1.622399 -1.52286 ]
1_1_0_0_1_0_1_0_175 [
-24.08685 0 -29.42813 ]
1_1_0_0_1_1_1_0_186 [
-1.665665 -0.2307523 -4.074597 ]
1_0_0_0_0_0_0_0_1 [
-0.5880737 -1.945877 -1.198183 ]
1_1_0_0_1_0_1_1_210 [
-0.001396737 -6.574267 -21.30147 ]
1_1_0_1_0_1_1_0_221 [
-0.7456465 -1.893918 -0.980585 ]
1_0_0_0_0_0_1_1_42 [
-3.838613e-05 -10.23002 -13.01793 ]
1_0_0_0_0_0_1_1_43 [
-22.25132 0 -28.8467 ]
1_0_0_0_0_0_1_1_44 [
-6.688306 -0.001266626 -10.79875 ]
1_0_0_0_0_0_1_1_45 [
-0.429086 -2.197691 -1.436171 ]
1_0_0_0_0_0_1_1_46 [
-0.6683982 -1.928907 -1.072464 ]
1_0_0_0_1_0_0_1_47 [
-0.5767454 -1.972311 -1.206838 ]
1_0_0_0_1_0_0_1_48 [
-0.5789171 -1.965128 -1.206118 ]
1_0_0_0_1_0_0_1_49 [
-19.90514 0 -25.12686 ]
1_0_0_0_0_0_0_0_4 [
-4.768373e-07 -14.66496 -28.4888 ]
1_0_0_0_1_0_0_1_50 [
-0.01524216 -6.729354 -4.273614 ]
1_0_0_0_1_0_0_1_51 [
-3.576279e-07 -14.9054 -27.44406 ]
1_0_0_0_1_0_0_1_53 [
-0.003753785 -8.922103 -5.623135 ]
The format it is stored in is: <name>_<part> [<data points>]
I currently use a perl script to sort the datapoints.
perl -n00e '
while ( /([\d_]*)_(\d*) \s* \[ \s* (.*?) \s* \]/gmsx ) {
($name,$part,$datapoints) = ($1,$2,$3);
$hash{$name}{$part}=$datapoints;
}
while (($key,$v)=each %hash) {
print "$key [\n", (
map "${$v}{$_}\n", sort {$a<=>$b} keys %{$v}
), "]\n";
}
'
Which creates an output as such:
0_0_1_1_0_1_1_1 [
-0.5757762 -1.949812 -1.219321
-0.5732827 -1.974719 -1.212248
-0.005632018 -5.198827 -9.280998
-0.004484621 -7.180546 -5.595852
-1.776234e-05 -10.93515 -20.11548
-22.73301 0 -29.42717
-4.227753 -0.01532919 -7.374347
-3.396693 -0.05122549 -4.10732
-0.0008418526 -7.08029 -20.86733
-21.26725 0 -27.1029
-2.457597 -0.09611109 -5.11661
-5.492554 -0.00666456 -5.981491
-12.60927 -3.576285e-06 -15.31444
-0.5809742 -1.953598 -1.2077
-0.5807223 -1.969571 -1.200681
]
...
Which is correct, but the end square bracket should not be on a new line,
but be placed a space distance after the last data point has been printed.
It doesn't look like the Perl script itself explicitly makes a new line
but some of the commands are invoking a new line.. is it possible to negate this effect?
Here is what #bytepusher recommended in comments:
while (($key,$v)=each %hash) {
print "$key [\n", join("\n",
map "${$v}{$_}", sort {$a<=>$b} keys %{$v}
), " ]\n";
}

Update with inner join Postgresql

Because doing this update does not work for the where clause? The update does it for me all.
UPDATE ventas SET eav_id = 7
FROM ventas AS A
inner join ventasDetalle AS e on A.act_id = e.act_id and e.exp_id = A.exp_id
where a.eav_id = 1
update ventas a
set eav_id = 7
from ventasDetalle e
where a.eav_id = 1 and (a.act_id, a.exp_id) = (e.act_id, e.exp_id)
The Postgresql UPDATE syntax is:
[ WITH [ RECURSIVE ] with_query [, ...] ]
UPDATE [ ONLY ] table [ [ AS ] alias ]
SET { column = { expression | DEFAULT } |
( column [, ...] ) = ( { expression | DEFAULT } [, ...] ) } [, ...]
[ FROM from_list ]
[ WHERE condition | WHERE CURRENT OF cursor_name ]
[ RETURNING * | output_expression [ [ AS ] output_name ] [, ...] ]
So I think you want:
UPDATE ventas AS A
SET eav_id = 7
FROM ventasDetalle AS e
WHERE (A.act_id = e.act_id and e.exp_id = A.exp_id)

Sudden Mongodb high connections/queues, db completely freezes

The issue
We have a strange issue on our mongodb setup. Sometimes we get peaks of high connections and high queues and the mongodb process stops responding if we let the queues and connections increase. We need to restart the instance using sigkill with htop.
It seems that there is a system limit / mongodb configuration blocking mongodb from operating, because hardware resources are ok. Versions of this issue happening on stand alone and then replica set on production servers. Details ahead.
About the software environment
This is a stand alone mongodb instance (not sharded nor replica sets), it's operating on a dedicated machine, and it's queried by other machines. I'm using mongodb-linux-x86_64-2.6.11 under Debian 7.7.
The machines querying mongo are using Django==1.7.4, Mongoengine=0.10.1 with pymongo==2.8.
On the Django settings.py file I'm connecting to the database using the following lines:
from mongoengine import connect
connect(
MONGO_DB,
username = MONGO_USER,
password = MONGO_PWD,
host = MONGO_HOST,
port = MONGO_PORT
)
MMS Stats
As you can see in the following img from the MMS service we have peaks on connections and queques:
When this happens, our mongodb process completely freezes. We must use SIGKILL to restart mongodb, which is really bad.
In the image there are 3 freeze events.
As the img shows, when this happens, we have a peak on Non-Mapped Virtual Memory too.
Also we spotted an increase on the Btree chart around the 2nd and 3rd freeze.
We have checked the logs, but there is no suspicious query, also the Opcounters don't skyrocket, it seems that there are no more queries than usual.
Here is another screenshot on the same bug but on another day/time:
On all the cases, the lock on the DB is not significantly increasing, it has a peak but not reaching even 4%:
OpCounter drops to zero, it seems that every op goes to the mongodb queque, so the database creates new connections to try to execute new requests, all of them going to the queue as well.
Machine Resources
Regarding hardware, the machine is a Google Cloud Compute instance with 4 Intel Xeon Cores, 16 Gb ram, 100 GB SSD disk.
No noticeable high network/io/CPU/ram issues detected, no peaks on resources, even when the mongod process is frozen.
MySQL on another machine also gets affected
Also we detect that at the same time of this mongod peak on queques and connections, we also get a spike on mysql connections, which is running on another machine. When I kill the mongodb process, all the mysql connections are released too (without doing a mysql restart).
ulimit
I increased system limits, to see if that was the cause of the issue but it seems that this did not fix the problem.
I set up everything as recommended on this MongoDB article. The spike on connections continue. I'm trying to find a way to debug where are this connections coming from.
$ ulimit -a
core file size (blocks, -c) unlimited
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 60240
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 409600
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 60240
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
db.currentOp
I just added a shell scripts that runs every 1 second with the following:
var ops = db.currentOp().inprog
if (ops !== undefined && ops.length > 0){
ops.forEach(function(op){
if(op.secs_running > 0) printjson(op);
})
}
The log does not report any operation that is taking more than 1 second to execute. I was thinking about a process taking long time on something but it seems that is not the case.
MongoDB Logs
Regarding the mongodb.log, here is the full mongodb log around the problem.
It just happens on log line 361. There the connections start to go up, and no more queries get executed. Also I cant call the mongo shell, it says:
[Wed Feb 10 15:46:01 UTC 2016] 2016-02-10T15:48:31.940+0000 DBClientCursor::init call() failed
2016-02-10T15:48:31.941+0000 Error: DBClientBase::findN: transport error: 127.0.0.1:27000 ns: admin.$cmd query: { whatsmyuri: 1 } at src/mongo/shell/mongo.js:148
Log extract
2016-02-10T15:41:39.930+0000 [initandlisten] connection accepted from 10.240.0.3:56611 #3665 (79 connections now open)
2016-02-10T15:41:39.930+0000 [conn3665] command admin.$cmd command: getnonce { getnonce: 1 } keyUpdates:0 numYields:0 reslen:65 0ms
2016-02-10T15:41:39.930+0000 [conn3665] command admin.$cmd command: ping { ping: 1 } keyUpdates:0 numYields:0 reslen:37 0ms
2016-02-10T15:41:39.992+0000 [conn3529] command db.$cmd command: count { count: "notification", fields: null, query: { read: false, recipient: 310 } } planSummary: IXSCAN { recipient: 1 } keyUpdates:0 numYields:0 locks(micros) r:215 reslen:48 0ms
2016-02-10T15:41:40.038+0000 [conn2303] query db.column query: { _id: ObjectId('56b395dfbe66324cbee550b8'), client_id: 20 } planSummary: IXSCAN { _id: 1 } ntoreturn:2 ntoskip:0 nscanned:1 nscannedObjects:1 keyUpdates:0 numYields:0 locks(micros) r:116 nreturned:1 reslen:470 0ms
2016-02-10T15:41:40.044+0000 [conn1871] update db.column query: { _id: ObjectId('56b395dfbe66324cbee550b8') } update: { $set: { last_request: new Date(1455118900040) } } nscanned:1 nscannedObjects:1 nMatched:1 nModified:1 fastmod:1 keyUpdates:0 numYields:0 locks(micros) w:126 0ms
2016-02-10T15:41:40.044+0000 [conn1871] command db.$cmd command: update { update: "column", writeConcern: { w: 1 }, updates: [ { q: { _id: ObjectId('56b395dfbe66324cbee550b8') }, u: { $set: { last_request: new Date(1455118900040) } }, multi: false, upsert: true } ] } keyUpdates:0 numYields:0 reslen:55 0ms
2016-02-10T15:41:40.048+0000 [conn1875] query db.user query: { sn: "mobile", client_id: 20, uid: "56990023700" } planSummary: IXSCAN { client_id: 1, uid: 1, sn: 1 } ntoreturn:2 ntoskip:0 nscanned:1 nscannedObjects:1 keyUpdates:0 numYields:0 locks(micros) r:197 nreturned:1 reslen:303 0ms
2016-02-10T15:41:40.056+0000 [conn2303] Winning plan had zero results. Not caching. ns: db.case query: { sn: "mobile", client_id: 20, created: { $gt: new Date(1454295600000), $lt: new Date(1456800900000) }, deleted: false, establishment_users: { $all: [ ObjectId('5637640afefa2654b5d863e3') ] }, is_closed: true, updated_time: { $gt: new Date(1455045840000) } } sort: { updated_time: 1 } projection: {} skip: 0 limit: 15 winner score: 1.0003 winner summary: IXSCAN { client_id: 1, is_closed: 1, deleted: 1, updated_time: 1 }
2016-02-10T15:41:40.057+0000 [conn2303] query db.case query: { $query: { sn: "mobile", client_id: 20, created: { $gt: new Date(1454295600000), $lt: new Date(1456800900000) }, deleted: false, establishment_users: { $all: [ ObjectId('5637640afefa2654b5d863e3') ] }, is_closed: true, updated_time: { $gt: new Date(1455045840000) } }, $orderby: { updated_time: 1 } } planSummary: IXSCAN { client_id: 1, is_closed: 1, deleted: 1, updated_time: 1 } ntoreturn:15 ntoskip:0 nscanned:26 nscannedObjects:26 keyUpdates:0 numYields:0 locks(micros) r:5092 nreturned:0 reslen:20 5ms
2016-02-10T15:41:40.060+0000 [conn300] command db.$cmd command: count { count: "notification", fields: null, query: { read: false, recipient: 309 } } planSummary: IXSCAN { recipient: 1 } keyUpdates:0 numYields:0 locks(micros) r:63 reslen:48 0ms
2016-02-10T15:41:40.133+0000 [initandlisten] connection accepted from 127.0.0.1:43266 #3666 (80 connections now open)
2016-02-10T15:41:40.133+0000 [conn3666] command admin.$cmd command: whatsmyuri { whatsmyuri: 1 } ntoreturn:1 keyUpdates:0 numYields:0 reslen:62 0ms
2016-02-10T15:41:40.134+0000 [conn3666] command db.$cmd command: getnonce { getnonce: 1 } ntoreturn:1 keyUpdates:0 numYields:0 reslen:65 0ms
2016-02-10T15:41:40.134+0000 [conn3666] authenticate db: db { authenticate: 1, nonce: "xxx", user: "xxx", key: "xxx" }
2016-02-10T15:41:40.134+0000 [conn3666] command db.$cmd command: authenticate { authenticate: 1, nonce: "xxx", user: "xxx", key: "xxx" } ntoreturn:1 keyUpdates:0 numYields:0 reslen:82 0ms
2016-02-10T15:41:40.136+0000 [conn3666] end connection 127.0.0.1:43266 (79 connections now open)
2016-02-10T15:41:40.146+0000 [conn3051] command db.$cmd command: count { count: "notification", fields: null, query: { read: false, recipient: 301 } } planSummary: IXSCAN { recipient: 1 } keyUpdates:0 numYields:0 locks(micros) r:284 reslen:48 0ms
2016-02-10T15:41:40.526+0000 [conn3529] query db.column query: { _id: ObjectId('56a8d864be6632718f9fb087'), client_id: 1 } planSummary: IXSCAN { _id: 1 } ntoreturn:2 ntoskip:0 nscanned:1 nscannedObjects:1 keyUpdates:0 numYields:0 locks(micros) r:176 nreturned:1 reslen:440 0ms
2016-02-10T15:41:40.529+0000 [conn3529] update db.column query: { _id: ObjectId('56a8d864be6632718f9fb087') } update: { $set: { last_request: new Date(1455118900527) } } nscanned:1 nscannedObjects:1 nMatched:1 nModified:1 fastmod:1 keyUpdates:0 numYields:0 locks(micros) w:61 0ms
2016-02-10T15:41:40.529+0000 [conn3529] command db.$cmd command: update { update: "column", writeConcern: { w: 1 }, updates: [ { q: { _id: ObjectId('56a8d864be6632718f9fb087') }, u: { $set: { last_request: new Date(1455118900527) } }, multi: false, upsert: true } ] } keyUpdates:0 numYields:0 reslen:55 0ms
2016-02-10T15:41:40.531+0000 [conn3529] query db.user query: { sn: "email", client_id: 1, uid: "asdasdasdasdas" } planSummary: IXSCAN { client_id: 1, uid: 1, sn: 1 } ntoreturn:2 ntoskip:0 nscanned:1 nscannedObjects:1 keyUpdates:0 numYields:0 locks(micros) r:278 nreturned:1 reslen:285 0ms
2016-02-10T15:41:40.546+0000 [conn3529] Winning plan had zero results. Not caching. ns: db.case query: { answered: true, sn: "email", client_id: 1, establishment_users: { $all: [ ObjectId('5669b930fefa2626db389c0e') ] }, deleted: false, is_closed: { $ne: true } } sort: { updated_time: -1 } projection: {} skip: 0 limit: 1 winner score: 1.0003 winner summary: IXSCAN { client_id: 1, establishment_users: 1, updated_time: 1 }
2016-02-10T15:41:40.547+0000 [conn3529] query db.case query: { $query: { answered: true, sn: "email", client_id: 1, establishment_users: { $all: [ ObjectId('5669b930fefa2626db389c0e') ] }, deleted: false, is_closed: { $ne: true } }, $orderby: { updated_time: -1 } } planSummary: IXSCAN { client_id: 1, establishment_users: 1, updated_time: 1 } ntoskip:0 nscanned:103 nscannedObjects:103 keyUpdates:0 numYields:0 locks(micros) r:9410 nreturned:0 reslen:20 9ms
2016-02-10T15:41:40.557+0000 [conn3529] Winning plan had zero results. Not caching. ns: db.case query: { answered: true, sn: "email", client_id: 1, establishment_users: { $all: [ ObjectId('5669b930fefa2626db389c0e') ] }, deleted: false, is_closed: { $ne: true } } sort: { updated_time: -1 } projection: {} skip: 0 limit: 15 winner score: 1.0003 winner summary: IXSCAN { client_id: 1, establishment_users: 1, updated_time: 1 }
2016-02-10T15:41:40.558+0000 [conn3529] query db.case query: { $query: { answered: true, sn: "email", client_id: 1, establishment_users: { $all: [ ObjectId('5669b930fefa2626db389c0e') ] }, deleted: false, is_closed: { $ne: true } }, $orderby: { updated_time: -1 } } planSummary: IXSCAN { client_id: 1, establishment_users: 1, updated_time: 1 } ntoreturn:15 ntoskip:0 nscanned:103 nscannedObjects:103 keyUpdates:0 numYields:0 locks(micros) r:7572 nreturned:0 reslen:20 7ms
2016-02-10T15:41:40.569+0000 [conn3028] command db.$cmd command: count { count: "notification", fields: null, query: { read: false, recipient: 145 } } planSummary: IXSCAN { recipient: 1 } keyUpdates:0 numYields:0 locks(micros) r:237 reslen:48 0ms
2016-02-10T15:41:40.774+0000 [conn3053] command db.$cmd command: count { count: "notification", fields: null, query: { read: false, recipient: 143 } } planSummary: IXSCAN { recipient: 1 } keyUpdates:0 numYields:0 locks(micros) r:372 reslen:48 0ms
2016-02-10T15:41:41.056+0000 [conn22] command admin.$cmd command: ping { ping: 1 } keyUpdates:0 numYields:0 reslen:37 0ms
#########################
HERE THE PROBLEM STARTS
#########################
2016-02-10T15:41:41.175+0000 [initandlisten] connection accepted from 127.0.0.1:43268 #3667 (80 connections now open)
2016-02-10T15:41:41.212+0000 [initandlisten] connection accepted from 10.240.0.6:46021 #3668 (81 connections now open)
2016-02-10T15:41:41.213+0000 [conn3668] command db.$cmd command: getnonce { getnonce: 1 } keyUpdates:0 numYields:0 reslen:65 0ms
2016-02-10T15:41:41.213+0000 [conn3668] authenticate db: db { authenticate: 1, user: "xxx", nonce: "xxx", key: "xxx" }
2016-02-10T15:41:41.213+0000 [conn3668] command db.$cmd command: authenticate { authenticate: 1, user: "xxx", nonce: "xxx", key: "xxx" } keyUpdates:0 numYields:0 reslen:82 0ms
2016-02-10T15:41:41.348+0000 [initandlisten] connection accepted from 10.240.0.6:46024 #3669 (82 connections now open)
2016-02-10T15:41:41.349+0000 [conn3669] command db.$cmd command: getnonce { getnonce: 1 } keyUpdates:0 numYields:0 reslen:65 0ms
2016-02-10T15:41:41.349+0000 [conn3669] authenticate db: db { authenticate: 1, user: "xxx", nonce: "xxx", key: "xxx" }
2016-02-10T15:41:41.349+0000 [conn3669] command db.$cmd command: authenticate { authenticate: 1, user: "xxx", nonce: "xxx", key: "xxx" } keyUpdates:0 numYields:0 reslen:82 0ms
2016-02-10T15:41:43.620+0000 [initandlisten] connection accepted from 10.240.0.6:46055 #3670 (83 connections now open)
2016-02-10T15:41:43.621+0000 [conn3670] command db.$cmd command: getnonce { getnonce: 1 } keyUpdates:0 numYields:0 reslen:65 0ms
2016-02-10T15:41:43.621+0000 [conn3670] authenticate db: db { authenticate: 1, user: "xxx", nonce: "xxx", key: "xxx" }
2016-02-10T15:41:43.621+0000 [conn3670] command db.$cmd command: authenticate { authenticate: 1, user: "xxx", nonce: "xxx", key: "xxx" } keyUpdates:0 numYields:0 reslen:82 0ms
2016-02-10T15:41:43.655+0000 [initandlisten] connection accepted from 10.240.0.6:46058 #3671 (84 connections now open)
2016-02-10T15:41:43.656+0000 [conn3671] command db.$cmd command: getnonce { getnonce: 1 } keyUpdates:0 numYields:0 reslen:65 0ms
2016-02-10T15:41:43.656+0000 [conn3671] authenticate db: db { authenticate: 1, user: "xxx", nonce: "xxx", key: "xxx" }
2016-02-10T15:41:43.656+0000 [conn3671] command db.$cmd command: authenticate { authenticate: 1, user: "xxx", nonce: "xxx", key: "xxx" } keyUpdates:0 numYields:0 reslen:82 0ms
2016-02-10T15:41:44.045+0000 [initandlisten] connection accepted from 10.240.0.6:46071 #3672 (85 connections now open)
2016-02-10T15:41:44.045+0000 [conn3672] command db.$cmd command: getnonce { getnonce: 1 } keyUpdates:0 numYields:0 reslen:65 0ms
2016-02-10T15:41:44.046+0000 [conn3672] authenticate db: db { authenticate: 1, user: "xxx", nonce: "xxx", key: "xxx" }
2016-02-10T15:41:44.046+0000 [conn3672] command db.$cmd command: authenticate { authenticate: 1, user: "xxx", nonce: "xxx", key: "xxx" } keyUpdates:0 numYields:0 reslen:82 0ms
2016-02-10T15:41:44.083+0000 [initandlisten] connection accepted from 10.240.0.6:46073 #3673 (86 connections now open)
2016-02-10T15:41:44.084+0000 [conn3673] command db.$cmd command: getnonce { getnonce: 1 } keyUpdates:0 numYields:0 reslen:65 0ms
2016-02-10T15:41:44.084+0000 [conn3673] authenticate db: db { authenticate: 1, user: "xxx", nonce: "xxx", key: "xxx" }
2016-02-10T15:41:44.084+0000 [conn3673] command db.$cmd command: authenticate { authenticate: 1, user: "xxx", nonce: "xxx", key: "xxx" } keyUpdates:0 numYields:0 reslen:82 0ms
2016-02-10T15:41:44.182+0000 [initandlisten] connection accepted from 10.240.0.6:46076 #3674 (87 connections now open)
2016-02-10T15:41:44.182+0000 [conn3674] command db.$cmd command: getnonce { getnonce: 1 } keyUpdates:0 numYields:0 reslen:65 0ms
Collection Information
Currently our database contains 163 collections. The important ones are messages, column and cases, this are the ones that get heavy inserts, updates and queries on. The rest if for analytics and are many collections of about 100 records each:
{
"ns" : "db.message",
"count" : 2.96615e+06,
"size" : 3906258304.0000000000000000,
"avgObjSize" : 1316,
"storageSize" : 9305935856.0000000000000000,
"numExtents" : 25,
"nindexes" : 21,
"lastExtentSize" : 2.14643e+09,
"paddingFactor" : 1.0530000000000086,
"systemFlags" : 0,
"userFlags" : 1,
"totalIndexSize" : 7952525392.0000000000000000,
"indexSizes" : {
"_id_" : 1.63953e+08,
"client_id_1_sn_1_mid_1" : 3.16975e+08,
"client_id_1_created_1" : 1.89086e+08,
"client_id_1_recipients_1_created_1" : 4.3861e+08,
"client_id_1_author_1_created_1" : 2.29713e+08,
"client_id_1_kind_1_created_1" : 2.37088e+08,
"client_id_1_answered_1_created_1" : 1.90934e+08,
"client_id_1_is_mention_1_created_1" : 1.8674e+08,
"client_id_1_has_custom_data_1_created_1" : 1.9566e+08,
"client_id_1_assigned_1_created_1" : 1.86838e+08,
"client_id_1_published_1_created_1" : 1.94352e+08,
"client_id_1_sn_1_created_1" : 2.3681e+08,
"client_id_1_thread_root_1" : 1.88089e+08,
"client_id_1_case_id_1" : 1.89266e+08,
"client_id_1_sender_id_1" : 1.5182e+08,
"client_id_1_recipient_id_1" : 1.49711e+08,
"client_id_1_mid_1_sn_1" : 3.17662e+08,
"text_text_created_1" : 3320641520.0000000000000000,
"client_id_1_sn_1_kind_1_recipient_id_1_created_1" : 3.15226e+08,
"client_id_1_sn_1_thread_root_1_created_1" : 3.06526e+08,
"client_id_1_case_id_1_created_1" : 2.46825e+08
},
"ok" : 1.0000000000000000
}
{
"ns" : "db.case",
"count" : 497661,
"size" : 5.33111e+08,
"avgObjSize" : 1071,
"storageSize" : 6.29637e+08,
"numExtents" : 16,
"nindexes" : 34,
"lastExtentSize" : 1.68743e+08,
"paddingFactor" : 1.0000000000000000,
"systemFlags" : 0,
"userFlags" : 1,
"totalIndexSize" : 8.46012e+08,
"indexSizes" : {
"_id_" : 2.30073e+07,
"client_id_1" : 1.99985e+07,
"is_closed, deleted_1" : 1.31061e+07,
"is_closed_1" : 1.36948e+07,
"sn_1" : 2.1274e+07,
"deleted_1" : 1.39728e+07,
"created_1" : 1.97777e+07,
"current_assignment_1" : 4.20819e+07,
"assigned_1" : 1.33678e+07,
"commented_1" : 1.36049e+07,
"has_custom_data_1" : 1.42426e+07,
"sentiment_start_1" : 1.36049e+07,
"sentiment_finish_1" : 1.37275e+07,
"updated_time_1" : 2.02192e+07,
"identifier_1" : 1.73822e+07,
"important_1" : 1.38256e+07,
"answered_1" : 1.41772e+07,
"client_id_1_is_closed_1_deleted_1_updated_time_1" : 2.90248e+07,
"client_id_1_is_closed_1_updated_time_1" : 2.86569e+07,
"client_id_1_sn_1_updated_time_1" : 3.58436e+07,
"client_id_1_deleted_1_updated_time_1" : 2.8477e+07,
"client_id_1_updated_time_1" : 2.79619e+07,
"client_id_1_current_assignment_1_updated_time_1" : 5.6071e+07,
"client_id_1_assigned_1_updated_time_1" : 2.87713e+07,
"client_id_1_commented_1_updated_time_1" : 2.86896e+07,
"client_id_1_has_custom_data_1_updated_time_1" : 2.88286e+07,
"client_id_1_sentiment_start_1_updated_time_1" : 2.87223e+07,
"client_id_1_sentiment_finish_1_updated_time_1" : 2.88776e+07,
"client_id_1_identifier_1_updated_time_1" : 3.48216e+07,
"client_id_1_important_1_updated_time_1" : 2.88776e+07,
"client_id_1_answered_1_updated_time_1" : 2.85669e+07,
"client_id_1_establishment_users_1_updated_time_1" : 3.93838e+07,
"client_id_1_identifier_1" : 1.86413e+07,
"client_id_1_sn_1_users_1_updated_time_1" : 4.47309e+07
},
"ok" : 1.0000000000000000
}
{
"ns" : "db.column",
"count" : 438,
"size" : 218672,
"avgObjSize" : 499,
"storageSize" : 696320,
"numExtents" : 4,
"nindexes" : 2,
"lastExtentSize" : 524288,
"paddingFactor" : 1.0000000000000000,
"systemFlags" : 0,
"userFlags" : 1,
"totalIndexSize" : 65408,
"indexSizes" : {
"_id_" : 32704,
"client_id_1_owner_1" : 32704
},
"ok" : 1.0000000000000000
}
Mongostat
Here is some of the lines we have running mongostat during normal operation:
insert query update delete getmore command flushes mapped vsize res faults locked db idx miss % qr|qw ar|aw netIn netOut conn time
*0 34 2 *0 0 10|0 0 32.6g 65.5g 1.18g 0 db:0.1% 0 0|0 0|0 4k 39k 87 20:44:44
2 31 13 *0 0 7|0 0 32.6g 65.5g 1.17g 3 db:0.8% 0 0|0 0|0 9k 36k 87 20:44:45
1 18 2 *0 0 5|0 0 32.6g 65.5g 1.12g 0 db:0.4% 0 0|0 0|0 3k 18k 87 20:44:46
5 200 57 *0 0 43|0 0 32.6g 65.5g 1.13g 12 db:2.3% 0 0|0 0|0 46k 225k 86 20:44:47
1 78 23 *0 0 5|0 0 32.6g 65.5g 1.01g 1 db:1.6% 0 0|0 0|0 18k 313k 86 20:44:48
*0 10 1 *0 0 5|0 0 32.6g 65.5g 1004m 0 db:0.2% 0 0|0 1|0 1k 8k 86 20:44:49
3 48 23 *0 0 11|0 0 32.6g 65.5g 1.05g 4 db:1.1% 0 0|0 0|0 16k 48k 86 20:44:50
2 38 13 *0 0 8|0 0 32.6g 65.5g 1.01g 8 db:0.9% 0 0|0 0|0 10k 76k 86 20:44:51
3 28 16 *0 0 9|0 0 32.6g 65.5g 1.01g 7 db:1.1% 0 0|0 1|0 11k 62k 86 20:44:52
*0 9 4 *0 0 8|0 0 32.6g 65.5g 1022m 1 db:0.4% 0 0|0 0|0 3k 6k 87 20:44:53
insert query update delete getmore command flushes mapped vsize res faults locked db idx miss % qr|qw ar|aw netIn netOut conn time
3 107 34 *0 0 6|0 0 32.6g 65.5g 1.02g 1 db:1.1% 0 0|0 0|0 23k 107k 87 20:44:54
4 65 37 *0 0 8|0 0 32.6g 65.5g 2.69g 57 db:6.2% 0 0|0 0|0 24k 126k 87 20:44:55
9 84 45 *0 0 8|0 0 32.6g 65.5g 2.63g 17 db:5.3% 0 0|0 1|0 32k 109k 87 20:44:56
4 84 47 *0 0 44|0 0 32.6g 65.5g 1.89g 10 db:5.9% 0 0|0 1|0 30k 146k 86 20:44:57
3 73 32 *0 0 9|0 0 32.6g 65.5g 2.58g 12 db:4.7% 0 0|0 0|0 20k 112k 86 20:44:58
2 165 48 *0 0 7|0 0 32.6g 65.5g 2.62g 7 db:1.3% 0 0|0 0|0 34k 147k 86 20:44:59
3 61 26 *0 0 12|0 0 32.6g 65.5g 2.2g 6 db:4.7% 0 0|0 1|0 19k 73k 86 20:45:00
3 252 64 *0 0 12|0 0 32.6g 65.5g 1.87g 85 db:3.2% 0 0|0 0|0 52k 328k 86 20:45:01
*0 189 40 *0 0 6|0 0 32.6g 65.5g 1.65g 0 db:1.6% 0 0|0 0|0 33k 145k 87 20:45:02
1 18 10 *0 0 5|0 0 32.6g 65.5g 1.55g 3 db:0.9% 0 0|0 0|0 6k 15k 87 20:45:03
insert query update delete getmore command flushes mapped vsize res faults locked db idx miss % qr|qw ar|aw netIn netOut conn time
1 50 11 *0 0 6|0 0 32.6g 65.5g 1.57g 6 db:0.8% 0 0|0 0|0 9k 63k 87 20:45:04
2 49 16 *0 0 6|0 0 32.6g 65.5g 1.56g 1 db:1.1% 0 0|0 0|0 12k 50k 87 20:45:05
1 35 11 *0 0 7|0 0 32.6g 65.5g 1.58g 1 db:0.9% 0 0|0 0|0 8k 41k 87 20:45:06
*0 18 2 *0 0 42|0 0 32.6g 65.5g 1.55g 0 db:0.4% 0 0|0 0|0 5k 19k 86 20:45:07
6 75 40 *0 0 11|0 0 32.6g 65.5g 1.56g 10 db:1.9% 0 0|0 0|0 27k 89k 86 20:45:08
6 60 35 *0 0 7|0 0 32.6g 65.5g 1.89g 5 db:1.5% 0 0|0 1|0 23k 101k 86 20:45:09
2 17 14 *0 0 7|0 0 32.6g 65.5g 1.9g 0 db:1.3% 0 0|0 1|0 8k 29k 86 20:45:10
2 35 7 *0 0 4|0 0 32.6g 65.5g 1.77g 1 db:1.3% 0 0|0 0|0 7k 60k 86 20:45:12
4 50 28 *0 0 10|0 0 32.6g 65.5g 1.75g 10 db:2.0% 0 0|0 0|0 19k 79k 87 20:45:13
*0 3 1 *0 0 5|0 0 32.6g 65.5g 1.63g 0 .:0.7% 0 0|0 0|0 1k 4k 87 20:45:14
insert query update delete getmore command flushes mapped vsize res faults locked db idx miss % qr|qw ar|aw netIn netOut conn time
5 77 35 *0 0 8|0 0 32.6g 65.5g 1.7g 13 db:3.0% 0 0|0 0|0 23k 124k 88 20:45:15
3 35 18 *0 0 7|0 0 32.6g 65.5g 1.7g 5 db:0.8% 0 0|0 0|0 12k 43k 87 20:45:16
1 18 5 *0 0 11|0 0 32.6g 65.5g 1.63g 2 db:0.9% 0 0|0 0|0 5k 35k 87 20:45:17
3 33 21 *0 0 5|0 0 32.6g 65.5g 1.64g 3 db:0.8% 0 0|0 0|0 13k 32k 87 20:45:18
*0 25 4 *0 0 42|0 0 32.6g 65.5g 1.64g 0 db:0.3% 0 0|0 0|0 5k 34k 86 20:45:19
1 25 5 *0 0 5|0 0 32.6g 65.5g 1.65g 3 db:0.2% 0 0|0 0|0 5k 24k 86 20:45:20
12 88 65 *0 0 7|0 0 32.6g 65.5g 1.7g 25 db:4.2% 0 0|0 0|0 42k 121k 86 20:45:21
2 53 17 *0 0 4|0 0 32.6g 65.5g 1.65g 2 db:1.5% 0 0|0 0|0 12k 82k 86 20:45:22
1 9 6 *0 0 7|0 0 32.6g 65.5g 1.64g 1 db:1.0% 0 0|0 0|0 4k 13k 86 20:45:23
*0 6 2 *0 0 7|0 0 32.6g 65.5g 1.63g 0 db:0.1% 0 0|0 0|0 1k 5k 87 20:45:24
Replica Set: Updated on May 15th 2016
We migrated our stand alone instance to a replica set. 2 secondaries serving the reads and 1 primary doing the writes. All the machines on the replica set area snapshots of the original machine. What happened with this new configuration is that the issue changed and it's harder to detect.
It happens less frequently but instead of sky rocketing connections and queues, the whole replica set stops reading/writing, with no high connections, no queues no expensive operations at all. All request to the DB just time out. To fix the issue a SIGKILL to the mongodb process must be sent to all 3 machines.
Hi this is exact problem we faced too and its very difficult to tell exact root cause and requires us lot of to and fro from official mongo support to understand some common problems.
Most of mongo setups done on unix and they have limit connections from same user though mongo server stats we can see lot of connections available. You get to get this setting to max possible value https://www.mongodb.com/docs/manual/reference/ulimit/
While connecting most of time we use default insert or insert many which has write concern as 1. In sharded cluster while saving to primary node is fast it takes time to replicate to other nodes and there are many connections left open there. If your cluster is 2 primary in 1 region and 1 secondary in DR region then network latency can come to play. Better go with majority write concern to avoid issues
https://www.mongodb.com/docs/manual/reference/write-concern/
There is max connection pool property which if not set will be default to 100 connection pool. So you application will try to create 100 connections if it requires to store fast. Limit connection pool based on your application need. We have very huge volume around 1 lakh per min still with multiple services max 20-30 connections sufficient to store that much volume.
https://www.mongodb.com/docs/manual/reference/connection-string/
We still trying to make mongo sharded infrastructure stable but its not mongo db itself. Its overall infrastructure that's causing the problem.