Tuesday, August 28, 2018

find command find multiple extensions

find ./ -type f \( -iname \*.jpg -o -iname \*.png \)

php sending chunked encoding response

<?php
header("Transfer-encoding: chunked");
@apache_setenv('no-gzip', 1);
@ini_set('zlib.output_compression', 0);
@ini_set('implicit_flush', 1);
for ($i = 0; $i < ob_get_level(); $i++)  ob_end_flush();
ob_implicit_flush(1); flush();

function dump_chunk($chunk)
{
  printf("%x\r\n%s\r\n", strlen($chunk), $chunk);
  flush();
}

for ($i=0;$i<2;++$i) {
        $output = array();
        for ($i=0;$i<20;++$i) {
                $output[] = str_repeat("-=", 100);
        }
        dump_chunk(implode("\n", $output));
        usleep(500000);
}
dump_chunk("");
?>

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.






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


> 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.

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

Blog Archive