Tech C**P
15 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
Format a volume as XFS in Debian


First of all install xfsprogs:

apt-get install xfsprogs


Make sure your formatting a right drive! Use ls to list drives:

root@debian:~# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sda5 /dev/sdb /dev/sdb1 /dev/sdc

In this installation I will format the drive /sdc, I know this because this is a blank drive with no partitions.

Now we partition the drive with the help of fdisk. fdisk can be scary if you have never used it before, in order to partition the drive use the commands below. Note: this will create one big partition, use the values inside the brackets [] as a guide.

root@debian:~# fdisk /dev/sdb

Command (m for help): [n]
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): [p]
Partition number (1-4, default 1): [1]
First sector (2048-335544319, default 2048): [press Enter]
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-335544319, default 335544319): [press Enter]
Using default value 335544319

Command (m for help): [w]
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.


Because we installed xfsprogs we can make use of mkfs.xfs to format the partition we created in the step above. -L will label the drive as media:

root@debian:~# mkfs.xfs -L media /dev/sdc1


Create a mount point:

root@debian:/dev# mkdir /mnt/dat1


Mount the drive:

root@debian:~# mount -t xfs /dev/sdc1 /mnt/dat1


Let’s check the newly mounted volume, visible at the bottom:

root@debian:/dev# df -h

Filesystem Size Used Avail Use% Mounted on
/dev/sda1 50G 1.9G 46G 4% /
udev 80M 4.0K 80M 1% /dev
tmpfs 36M 272K 35M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 88M 0 88M 0% /run/shm
/dev/sdc1 160G 33M 160G 1% /mnt/dat1


To permanently mount the new volume every time the system boots you will need to edit and add a new entry to /etc/ fstab. You can use the echo command to easily add the new entry:

root@debian:# echo '/dev/sdc1 /mnt/dat1 xfs defaults 0 0' >> /etc/fstab


Or manually add the entry below to fstab with the text editor of your choice:

/dev/sdc1 /mnt/dat1 xfs defaults 0 0

XFS is a good file system for those of us working with large files. This is a recommended filesystem for those working with MongoDB wiredTiger too.

#linux #filesystem #xfs #fdisk #mount #df #fstab #xfsprogs #mkfs_xfs
Today I had to migrate the ODM class from CouchDB to MongoDB for a specific module. As we didn't combine logic into our backend database we easily changed db to MongoDB.

Go take a look at your code see whether you can change the backend DB easily from your current database to another database? Will you scratch your head when CTO says, ok we are moving to BlahDB, what would you do? How much flexibilty you have?

Some people may argue that we don't change backend DB that much and we do not ever change the backend DB! This a naive consideration and I would highly recommend to think over. Because this code change flexibility shows how well your structure is implemented. How well you have programmed.

#couchdb #mongodb
What is a HAR file?

The HAR file format is an evolving standard and the information contained within it is both flexible and extensible. You can expect a HAR file to include a breakdown of timings including:

- How long it takes to fetch DNS information

- How long each object takes to be requested

- How long it takes to connect to the server

- How long it takes to transfer assets from the server to the browser of each object


How To Get A HAR File?

By using chrome inspect element it is easy as pie. Just open inpect element, right click on one of the requests sent to server and click on Save as HAR with content and save the file on your system.

Now you need a tool to analyze the result. There is an online tool for that head over to link below:

- https://toolbox.googleapps.com/apps/har_analyzer/


In the website load your HAR file and click on Choose file and open your HAR file. It will give an insight on your request times, DNS response, etc.

#HAR #inspect_element
To check if the kernel knows about SSDs try:

for f in /sys/block/sd?/queue/rotational; do printf "$f is "; cat $f; done

When you run the command above, you will see results like below:

/sys/block/sda/queue/rotational is 1
/sys/block/sdb/queue/rotational is 1
/sys/block/sdc/queue/rotational is 0 <=== Only this is SSD!

#ssd #linux #hdd #rotational
In mongoDB you can check total available connections and the current connections to see if you have met the maximum available connections.

If there are numerous concurrent application requests, the database may have trouble keeping up with demand. If this is the case, then you will need to increase the capacity of your deployment.

For read-heavy applications, increase the size of your replica set and distribute read operations to secondary members.

For write-heavy applications, deploy sharding and add one or more shards to a sharded cluster to distribute load among mongod instances.

[test]> db.serverStatus().connections
{ "current" : 636, "available" : 50564, "totalCreated" : 1428309 }


#mongodb #serverStatus #connections
When the query criteria and the projection of a query include only the indexed fields, MongoDB returns results directly from the index without scanning any documents or bringing documents into memory.
301 Redirects vs. 302 Redirects

Status 301 means that the resource (page) is moved permanently to a new location. The client/browser should not attempt to request the original location but use the new location from now on. (Mostly 301 vs 302 is important for indexing in search engines, as their crawlers take this into account and transfer PageRank when using 301)

Status 302 means that the resource is temporarily located somewhere else, and the client/browser should continue requesting the original url.

NOTE: becareful about your page rank when redirecting!

#redirect #301 #302
When you use set in Python it makes sure that your list is unique, but does not keep the insertion order of
the set. For that use the below python package:

https://pypi.python.org/pypi/orderedset

NOTE: becareful if you want to use it in production as it is 5 times slower than set!

#python #set #ordered_set #orderedset
It is best practice to always set server date/time to UTC. In debian in order to configure your time and set it to UTC, do as follow:

sudo dpkg-reconfigure tzdata

Now select None of the above or Etc and then press OK. Now select UTC. You're done.

To check your server date/time issue date command:

root@serv01:~# date
Mon Mar 5 11:20:59 UTC 2018


#date #dpkg-reconfigure #tzdata #UTC #timezone
In MongoDB it is suggested to turn atime to off. atime is set by Linux on each file accessed by applications. It is reported repeatedly that turning it off will improve disk performance on that partition.

To run off atime you need to set noatime on the partition you are placing mongoDB database files. Open /etc/fstab and look for your desired partition (mine is `/var`):

/dev/mapper/mongo--vg-var /var            xfs     defaults        0       2


Add noatime after defaults:

/dev/mapper/mongo--vg-var /var            xfs     defaults,noatime        0       2

Yours may be a little bit different. Now reboot your server using reboot --reboot.


Now you can check it by mount -l whether noatime is set or not:

/dev/mapper/mongo--vg-var on /var type xfs (rw,noatime,attr2,inode64,logbsize=256k,sunit=512,swidth=1024,noquota)

In the next post we test this using touch command in Linux.

#mongodb #mongo #noatime #atime #xfs #linux #fstab #mount
This media is not supported in your browser
VIEW IN TELEGRAM
صفحه لاگین خلاقانه 😍