grep -r -E -o ".{0,10}needle.{0,10}" *
Wednesday, August 15, 2018
Wednesday, August 8, 2018
Azure 70 534 notes
https://www.safaribooksonline.com/library/view/Exam+Ref+70-534+Architecting+Microsoft+Azure+Solutions/9780735697706/
Compute instances:
RDMA capable backend
Azure Batch and TVM
- for long running tasks
How do Homogeneous instances handle session replication?
- Sticky sessions
- External starte store(for e.g. redis)
Scheduled vs Reactive scaling (reactive means there will be some delay in scaling)
--------------
Azure Traffic Manager - redirects traffic based on round robin/performance etc. Triggered in DNS phase, so the actual traffic doesn't pass through it.
--------------
Azure Traffic Manager - redirects traffic based on round robin/performance etc. Triggered in DNS phase, so the actual traffic doesn't pass through it.
Friday, July 6, 2018
Mongodb sample queries
Assuming DB name is "master" and table(collection) name is "top"
Command line:
> use master
> db.getCollection("top").count() (or better db.top.count())
> db.getCollection("top").find({"query" : "best goa beaches"}).count();
> db.getCollection("top").find({"query" : "best goa beaches", "is_last_page": true}).count();
> db.getCollection("top").drop()
> db.places.distinct('result.place_id').length //distinct on nested field and length(not count)
> db.dm.find({ dist: { $lt: 5000 } ,type1: 'zoo', type2:'hotel'} ).count(); //less than operator
PHP: $query_assoc = array();
$query_assoc['type1'] = 'zoo';
$query_assoc['type2'] = 'hotel';
$query_assoc['dist'] = array('$lt'=> $radius);
> db.places.find({ "result.place_id": { $in: ['ChIJYU0mP3W_vzsReXl288rhJ9M'] }},{"result.name":1} ) //find and project with "in" clause
> db.dm.find({g_dist: {$gt: 0}},{g_dist:1} ).sort({"g_dist":1}).limit(1) //find with projection and sort
Response: { "_id" : ObjectId("5b449e47a387a535a00013bb"), "g_dist" : 134 }
> db.places.find({place_type: {$exists: false}}).count() //whether the field exists?
> db.places.updateMany({eplace: 'Goa'}, {$set: {eplace: 'kk'}}) //update where
> db.places.distinct('result.place_id').length //distinct on nested field and length(not count)
> db.dm.find({ dist: { $lt: 5000 } ,type1: 'zoo', type2:'hotel'} ).count(); //less than operator
PHP: $query_assoc = array();
$query_assoc['type1'] = 'zoo';
$query_assoc['type2'] = 'hotel';
$query_assoc['dist'] = array('$lt'=> $radius);
> db.places.find({ "result.place_id": { $in: ['ChIJYU0mP3W_vzsReXl288rhJ9M'] }},{"result.name":1} ) //find and project with "in" clause
> db.dm.find({g_dist: {$gt: 0}},{g_dist:1} ).sort({"g_dist":1}).limit(1) //find with projection and sort
Response: { "_id" : ObjectId("5b449e47a387a535a00013bb"), "g_dist" : 134 }
> db.places.find({place_type: {$exists: false}}).count() //whether the field exists?
> db.places.updateMany({eplace: 'Goa'}, {$set: {eplace: 'kk'}}) //update where
> import/export
mongodump -d <database_name> -o <directory_backup>
mongorestore -d <database_name> <directory_backup>
PHP:
$manager = new MongoDB\Driver\Manager(); //localhost
$bulk = new MongoDB\Driver\BulkWrite;
$record = array("a" => "b");
$bulk->insert($record);
$manager->executeBulkWrite('master.top', $bulk); //write
getCount($manager, array('query' => $q, 'page' => $page));//get record count meeting the criteria
function getCount($manager, $q) {
$query = new MongoDB\Driver\Query($q);
$rows = $manager->executeQuery('master.top', $query);
$count = 0;
foreach($rows as $doc) {
++$count;
}
return $count;
}
Friday, June 8, 2018
CAP Theorem - Alternate explanation - nice article summary
https://codahale.com/you-cant-sacrifice-partition-tolerance/
1. Partition tolerance is not optional. It's a given - packets will
drop/communication errors are bound to happen between nodes.
2. So all you can choose is Availability or Consistency.
3. Choosing Consistency - You can stop accepting writes or only take
writes if the node is "Master" of the data to be written.
4. Choosing Availability - You can take all the writes but clients may
get "stale data".
2 more relevant metrices which better capture the performance
Yield & Harvest
Yield is similar to uptime but one major diff. If node is down for 1
second in peak/off-peak hours - uptime is same - but yield is vastly
different. Yield directly maps to what the user experienced. So Yield
= % of user requests served.
Harvest = available data/total data. If data lies on 3 nodes but
server was able to serve data from only 2 nodes => harvest = 66%
Now we need to decide whether faults impact yield or harvest.
Replicated systems tend to map faults to reduced yield - since fewer
requests will complete.
Partitioned systems will map faults to reduced harvest - since lesser
data will be available.
1. Partition tolerance is not optional. It's a given - packets will
drop/communication errors are bound to happen between nodes.
2. So all you can choose is Availability or Consistency.
3. Choosing Consistency - You can stop accepting writes or only take
writes if the node is "Master" of the data to be written.
4. Choosing Availability - You can take all the writes but clients may
get "stale data".
2 more relevant metrices which better capture the performance
Yield & Harvest
Yield is similar to uptime but one major diff. If node is down for 1
second in peak/off-peak hours - uptime is same - but yield is vastly
different. Yield directly maps to what the user experienced. So Yield
= % of user requests served.
Harvest = available data/total data. If data lies on 3 nodes but
server was able to serve data from only 2 nodes => harvest = 66%
Now we need to decide whether faults impact yield or harvest.
Replicated systems tend to map faults to reduced yield - since fewer
requests will complete.
Partitioned systems will map faults to reduced harvest - since lesser
data will be available.
Tuesday, June 5, 2018
vim line margin spacing etc
line spacing: set lsp=10
left margin: :set foldcolumn=3
then
:highlight FoldColumn guibg=white guifg=white
or
:highlight FoldColumn guibg=gray14 guifg=white
left margin: :set foldcolumn=3
then
:highlight FoldColumn guibg=white guifg=white
or
:highlight FoldColumn guibg=gray14 guifg=white
Tuesday, April 24, 2018
letsencrypt wildcard ssl certificate on Amazon Linux + Apache
mkdir certbot
cd certbot
chmod a+x certbot-auto
sudo ./certbot-auto certonly --server https://acme-v02.api.letsencrypt.org/directory --manual --preferred-challenges dns -d *.domainname.com
For putting TXT record in NameCheap:
In HostName, put _acme-challenge, in value put the string given on the command line.
To check whether the txt record is deployed:
dig -t txt _acme-challenge.domainname.com
Then in httpd.conf:
<VirtualHost *:443>
DocumentRoot "/var/www/html/somepath"
ServerName other.domainname.com
ServerAlias *. domainname .com
SSLCertificateFile /etc/letsencrypt/live/ domainname .com-0001/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/ domainname .com-0001/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/ domainname .com-0001/fullchain.pem
ErrorLog logs/ domainname -error_log
CustomLog logs/ domainname -access_log common
<Directory "/var/www/html/somepath">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Monday, April 23, 2018
Subscribe to:
Posts (Atom)