• ## Cryptocurrency Mining Rig - Power Supply Unit

I was looking around to see how to determine how much power consumption my rig would be. Well, there is never a definitive answer. Yet you can estimate from specification to get roughly guide.

1. Mainboard: 50W
2. CPU: 50-100W
3. RAM: 5W each stick
4. HDD: 10W each

That’s for regular parts. For GPU, there are several things to consider from PCI-e specification:

• Base power - one PCI-e slot has to be provide 75W.
• 6 Pin PCI Express power connector - maximum power delivery = 75W
• 8 Pin PCI Express power connector - maximum power delivery = 150W

From this information, you can tell that

• Gigabyte Radeon R9-280x, which has two power connectors: 6-pin and 8-pin connectors, can draw 75W (PCI-e slot) + 150W (8-pin) + 75W (6-pin) = 300W (total)
• Gigabyte HD 7870, which has 2 6-pin power connectors, can draw power 75W + 2*(75W) = 225W

For a regular mining rig, weak CPU, with 3 GPUs (7870):

• `50W` Mainboard
• `50W` CPU
• `5W` 4GB RAM
• 3*`225W` Gigabye 7870

You will end up having 50W+50W+5W+3*225W = 780W; however, you’d better have at least 20% extra power available which helps power supply unit (PSU) not to be in too heavy load at all time. This simply means you should buy at least 780W * 1.2 = 936W. Surely, you can’t find it, but 1000W PSU is close enough =) Questions?

• Does AX760i (Great PSU) which can provide 760W work with above example (which theoretically draws 780W) ? I’m sure it’s working. What we are calculating is the maximum power consumption your machine can draw. In practice, it’s never hit 100% mark, but why putting that heavy load on PSU? Its lifespan will get shorter no matter how good it is.
• What if my machine draw more power than PSU can provide? It depends. (1) Good PSU is likely to shut itself down immediately; (2) some PSU tries harder to provide its juice which cause a ripple. Random reboot or shutdown is likely the result. Lastly (3) PSU is exploded. It is not as bad as it sounds though. In fact, capacitors inside PSU will explode. You will hear and smell clearly if it’s gone. Don’t worry. Maybe a bit of smoke, but mostly your components shouldn’t be damaged, but you never know. :)

Note: Above product links in this post are affiliated ;)

• ## Cryptocurrency Mining Rig setup

Don’t ask me if it’s worth investment. I don’t know since difficulty and exchange rate change (drop?) everyday. It’s getting harder and harder to get even but it makes me feel building computer fun again. LoL

After trial and error, the painless route is to creating USB flash drive for it. Clone it for another rig. Of course, I use Xubuntu, I don’t know how to deal with Windows these days.

What you need:-

• Xubuntu - get x64 one – Xubuntu, not Ubuntu. Unity is weird
• 8GB or more Flash drive; it doesn’t necessarily need to be a fast one. Just make sure it’s not extraordinarily slow. (You need one extra for Xubuntu setup if you don’t burn Xubuntu ISO to CD)
• Mining Rig – Any hardware with AMD/ATI VGA cards, 4GB of RAM, any CPU would do it.
• 1x-to-16x PCI-e riser or 16x PCI-e riser – 1x-to-16x is preferred since better airflow preferred. Well, basically you don’t need this to get fully functional rig, but your rig will run so darn hot and it is NOT good at all.

What you don’t need:-

• From my experience, you don’t need any dummy plug.
• Powered 1x-to-16x PCI-e riser – some recommended it over unpowered but you only need if you have > 3 GPUs (or using 1x slot) since 75W each slot draw – GPU specification – from mainboard is pretty much putting load under mainboard, esp. you are using 1x PCI-e slot which by specification 1x slot can’t handle that much power (only 25W) while 16x is comfortably handled.

To build your mining rig is pretty much like every computer, but we choose to have only needed things, Mainboard, CPU, RAM, Flash drive, VGA cards, to save power as much as possible. If you like to know which hardware is better, you probably what to look at Mining hardware comparison. You should look at kH/s rate, the more the better, but IMHO you need to think of average kH/s of each GPU since the highest hash rate in that table means they overclocks their GPUs as well. To me, mining coins is long-term; need to be stable; run every at stock; keep temperature normal.

For the first time ever, you need to have monitor, keyboard or mouse.

• get into BIOS, `del` on POST and choose to boot with Xubuntu setup flash drive. Also, you might like to check option power on after power failure too. It’s very handy.
• Xubuntu setup process is pretty much painless, you mostly click many ‘next’ buttons to get it done. One thing you need an attention is Log in automatically checkbox. You need to make sure it’s checked.
• Reboot after setup is done. Now you need to test if it’s working by taking out Xubuntu setup flash drive out and let Xubuntu one boot up.
• If it boots into Xubuntu, we are on half way to success. If not, repeat above.
• Go to terminal and install GPU driver and necessary stuffs

\$ sudo apt-get update \$ sudo apt-get install byobu openssh-server fglrx-updates fglrx-amdcccle-updates fglrx-updates-dev

• Check if Xubuntu sees all your GPU

\$ sudo aticonfig –lsa

If you see every GPU, that’s good. If not, try to power off, check, re-insert your GPU again * Configure your GPU

``````\$ sudo mv /etc/X11/xorg.conf /etc/X11/xorg.conf.bak
\$ sudo aticonfig --adapter=all --initial
``````
• Reboot to verify if everything works

\$ sudo aticonfig –adapter=all –odgt

Next is `cgminer` part, download here. Please download 3.7.2 version since it’s the last version supporting `scrypt` which is likely to be protocol for most pool; otherwise, we need proxy in order to join any pool. This post will not cover that since I like to write how I setup and get it running automatically first.

``````\$ tar xjvf cgminer-3.7.2-x86_64-built.tar.bz2
``````

You end up having `cgminer-3.7.2-x86_64-built` directory if download from here. You can test whether it is working:

``````\$ cd cgminer-3.7.2-x86_64-built
\$ ./cgminer -n
[2014-02-20 13:08:06] CL Platform 0 vendor: Advanced Micro Devices, Inc.
[2014-02-20 13:08:06] CL Platform 0 name: AMD Accelerated Parallel Processing
[2014-02-20 13:08:06] CL Platform 0 version: OpenCL 1.2 AMD-APP (1214.3)
[2014-02-20 13:08:06] Platform 0 devices: 3
[2014-02-20 13:08:06] 	0	Pitcairn
[2014-02-20 13:08:06] 	1	Pitcairn
[2014-02-20 13:08:06] 	2	Tahiti
[2014-02-20 13:08:06] ADL Initialisation Error! Error -1!
[2014-02-20 13:08:06] 3 GPU devices max detected
[2014-02-20 13:08:06] USB all: found 9 devices - listing known devices
[2014-02-20 13:08:06] No known USB devices
``````
• `-n means listing all GPU devices`

If you don’t see all, you like to try `aticonfig` things above again.
My example rig above consisting of 2 * Gigabyte 7870 [Pitcairn] and 1 * Gigabyte 280x [Tahiti]. I just want to show that you can have different GPU in the same rig as long as your power supply unit can handle.

If you see all devices, that’s a good sign. Do not worry errors like above though. It’s working just fine and that’s you have everything you need to mine.

Up to this point, monitor, keyboard and mouse are useless. You can shut computer down and take them off. From now on, you plug your power and switch on at power supply, it should be able to turn on automatically and surely that’s what we intend to.

Running `cgminer` is the last thing left to do.

Well, I can’t cover everything, but Mining hardware comparison is where you can see other configurations which is a good guideline for trials and errors. For pool, if you don’t know anything, you will google a lot to see what the heck is pool. For me:

• If you want to mine LiteCoin (LTC), you go register and add worker at WeMineLtc.com. Some says they are too large pool already, but I say it’s very reliable and as newbie, you need to get familiar with mining process first. This is a good place to start.
• If you want to mine DogeCoin (DOGE), you go register and add worker at RapidHash. Very reliable service there.

You can also find small pools everywhere, but I used to try some of them and I don’t get coins at all after a week mining. -*- Maybe your mileage may vary. After registration, you will get:

• Statum Servers – usually on pools’ front page
• WeMineLTC index page: World-Wide Server (VARDIFF): `stratum+tcp://hot.wemineltc.com:3335`
• Rapidhash has an example command shown on first page: `stratum+tcp://stratum.rapidhash.net:3333`
• Worker user/password: it will usually be your username.xxx; for password, you can just use 1 or anything simple. If someone else want to mine for you, why not let them? haha You only keep account password and PIN safe. That’s enough.

Next you try running `cgminer`, command is something like this

``````\$ export DISPLAY=:0
\$ export GPU_MAX_ALLOC_PERCENT=100
\$ export GPU_USE_SYNC_OBJECTS=1
\$ ./cgminer --scrypt --no-submit-stale -o stratum+tcp://stratum.rapidhash.net:3333 -u username.worker -I 13 -w 256 --thread-concurrency 8192 --auto-fan --gpu-engine 980 --gpu-threads 2
``````
• `-I`means Intensity [0-20] more intensity usually means more hashes, but with 280x >13 intensity produces more invalids; well, trial and error after all.
• `-w 256`means worksize, I only see people use this value haha.
• `--thread-concurrency 8192` to set GPU thread concurrency for scrypt mining, larger doesn’t always mean more hashes though.
•  `--auto-fan` means let card adjust how fast fan is based on temperature. You could do like `--auto-fan --gpu-fan 30-85` to specify range fan should be also. People claimed that running 24 7 at max fan speed could kill fan in 2 months. Well, believe it or not? I don’t dare trying
• `--gpu-engine 980` means GPU clock speed; range setting like `--gpu-engine 980-1000` is also possible.
• `--gpu-threads 2` means number of threads per GPU (1 - 10)

Above you are setting one value per parameters. If you have many of the same card in your rig, that will be applied to all cards. However, if you want each card running different parameters, you could do like `-I 13,18 -w 256,256 --thread-concurrency 8192,12000 --auto-fan --gpu-engine 980,1050` to have different settings for each card. However, it’s better to run many `cgminer` instance if you have 2 different GPU by using `-d 2` means using only device number 2 (from `./cgminer -n` as shown above) or you can use `-d 0,1` to use this `cgminer` instance for device number 0 and 1.

When you get satisfied parameters, you can create a script file. For example, `mining.sh`

``````#!/bin/sh
export DISPLAY=:0
export GPU_MAX_ALLOC_PERCENT=100
export GPU_USE_SYNC_OBJECTS=1
cd /home/ninox/cgminer-3.7.2-x86_64-built
./cgminer --scrypt --no-submit-stale -o stratum+tcp://stratum.rapidhash.net:3333 -u ninox.w1 -p 1 -d 2 -I 13 -w 256 --thread-concurrency 8192 --auto-fan --gpu-fan 20-85 --gpu-engine 980 --gpu-threads 2
``````

Then make this file executable

``````\$ chmod +x mining.sh
``````

Verify if it works

``````\$ ./mining.sh
``````

You should see something like

``````cgminer version 3.7.2 - Started: [2014-02-19 11:42:25]
--------------------------------------------------------------------------------
(5s):699.9K (avg):684.5Kh/s | A:566864  R:4944  HW:0  WU:618.4/m
ST: 2  SS: 7  NB: 919  LW: 8874  GF: 1  RF: 0
Connected to stratum.rapidhash.net diff 128 with stratum as user ninox.w1
Block: 2102e8d1...  Diff:1.15K  Started: [03:17:01]  Best share: 2.18M
--------------------------------------------------------------------------------
[P]ool management [G]PU management [S]ettings [D]isplay options [Q]uit
GPU 0:  75.0C 100%    | OFF   / 5.000h/s | A:     0 R:   0 HW:0 WU:   0.0/m I:13
GPU 1:  73.0C  60%    | OFF   / 0.000h/s | A:     0 R:   0 HW:0 WU:   0.0/m I:13
GPU 2:  74.0C 3367RPM | 698.9K/684.5Kh/s | A:566864 R:4944 HW:0 WU: 618.4/m I:13
--------------------------------------------------------------------------------

[2014-02-20 03:16:24] Accepted 01a73a13 Diff 155/128 GPU 2 pool 0
[2014-02-20 03:16:29] Accepted 2b989e17 Diff 1.5K/128 GPU 2 pool 0
[2014-02-20 03:16:30] Accepted 01ed9e3c Diff 133/128 GPU 2 pool 0
[2014-02-20 03:16:36] Stratum from pool 0 detected new block
[2014-02-20 03:16:56] Accepted 01423a05 Diff 203/128 GPU 2 pool 0
[2014-02-20 03:17:01] Stratum from pool 0 detected new block
``````

Shown above is using Gigabyte R9-280x working alone. The ambient temperature is roughly 30ºC; at night with lower ambient temperature, I could push more hashes in 7x0, but in quite hot country, I don’t want to kill my GPU quickly by running at 8xºC always.

I’m impressed with 2 * Gigabyte 7870 more. With half a price of Gigabyte R9-280x, they are running smooothly at 42x kH/s each card at very low temperature.

``````cgminer version 3.7.2 - Started: [2014-02-19 11:43:02]
--------------------------------------------------------------------------------
(5s):823.8K (avg):844.7Kh/s | A:697728  R:4608  HW:0  WU:765.9/m
ST: 2  SS: 66  NB: 923  LW: 9081  GF: 1  RF: 1
Connected to stratum.rapidhash.net diff 128 with stratum as user ninox.w1
Block: a3b04227...  Diff:1.15K  Started: [03:20:46]  Best share: 289K
--------------------------------------------------------------------------------
[P]ool management [G]PU management [S]ettings [D]isplay options [Q]uit
GPU 0:  74.0C 100%    | 422.9K/422.5Kh/s | A:349488 R:2304 HW:0 WU: 382.8/m I:18
GPU 1:  73.0C  31%    | 423.0K/422.2Kh/s | A:348240 R:2304 HW:0 WU: 383.2/m I:18
GPU 2:  75.0C 3359RPM | OFF   / 0.000h/s | A:     0 R:   0 HW:0 WU:   0.0/m I:18
--------------------------------------------------------------------------------
``````

This is stock clock speed of 7870 while I have to underclock my R9-280x and put it on the outermost to get coldest air to retain 7x ºC or its temperature will rise to 8x ºC. As always, your mileage may vary.

Mining part is complete. Nonetheless, you would want to have it start automatically if your system fails. The easiest way to deal with is crontab. I like to have one script to run it.

`~/mining-cron.sh`

``````#!/bin/sh
sleep 40
screen -dmS miner280 /home/ninox/rapid-280.sh
sleep 40
screen -dmS miner7870 /home/ninox/rapid-2-7870.sh
``````

Don’t forget to make this file executable also.

``````\$ chmod +x mining-cron.sh
``````

Above means hold for 40 seconds then run `/home/ninox/rapid-280.sh` in `screen` named miner280 and hold for another 40 seconds before running another file in `screen` named miner7870. For those who do not know what `screen` is it’s a shell session which is always running in background. To check how session is, you could do:

``````\$ screen -r
There are several suitable screens on:
1892.miner7870	(02/19/2014 11:43:00 PM)	(Detached)
1680.miner280	(02/19/2014 11:42:20 PM)	(Detached)
Type "screen [-d] -r [pid.]tty.host" to resume one of them.
\$
``````
• To open specific screen using `screen -r miner7870` and
• `CTRL + a then d` to get out of that session without terminating the process.

Then putting in crontab

``````\$ crontab -e
@reboot /home/ninox/rapid-cronjob.sh
``````

This is setting cron job for your own user, not system.

• ## SSL with Nginx

`https` is pretty much preferred protocol over bare `http` nowadays and it gets very affordable for basic one sub-domain which you can get as low as \$9 a year. However, how to get and use one sometimes pretty much overkill although it is rather simple. Yeah, I keep forgetting since I don’t really have to do that frequent.

Depending on where you purchase SSL certificate, I pick namecheap. I don’t have any reason for it, but they are as reliable as it could be. GoDaddy, to me, is okay–they tend to have lower renewal cost for domain too. Back to SSL certificate, you need to generate a CSR (Certificate Signing Request) to ask for SSL. I’m using openSSL.

``````# openssl req -nodes -newkey rsa:2048 -keyout mywhatever.key -out whatever.csr
``````

A series of question will be asked:

``````Country Name (2 letter code) [AU]: US
State or Province Name (full name) [Some-State]: NH
Locality Name (eg, city) []: Atkinson
Organization Name (eg, company) [Internet Widgits Pty Ltd]: 10ninox Ltd
Organizational Unit Name (eg, section) []:
Common Name (eg, YOUR name) []: 10ninox.com
Email Address []:

A challenge password []:
An optional company name []:
``````

Some fields can be left blank, but you pretty much like to answer all for your own credential. The thing is you should leave challenge password empty, otherwise, you will have to type that every time your Nginx reload or restart. Then you get 2 file `mywhatever.key` and `whatever.csr`

Back to namecheap, issue your SSL, then paste content of `whatever.csr` to the form. Wait for a verification step via email. Then you would get `your_site.zip` with following mails. The whole process should take less than 10-15 minutes as far as my experience goes.

Now you have to extract `your_site.zip` which contains several files something like

• 10ninox_com.crt
• PositiveSSLCA2.crt
• AddTrustExternalCARoot.crt

Merge those files into one, `10ninox-ssl-bundle.csr` or whatever name you want.

``````\$ cat 10ninox_com.crt PositiveSSLCA2.crt AddTrustExternalCARoot.crt > 10ninox-ssl-bundle.csr
``````

Then copy the bundle file and `mywhatever.key` we got earlier to a directory in your server; location is up to you. There is no restricted whatsoever. The last process is to setup Nginx to know where SSL certificate is in Nginx virtualhost file (likely to be `/etc/nginx/sites-available/10ninox.com` for Debian)

This is an example how to configure one:

``````server {
listen 443;

ssl on;
ssl_certificate /opt/projects/10ninox/ssl/10ninox-ssl-bundle.csr;
ssl_certificate_key /opt/projects/10ninox/ssl/mywhatever.key;
ssl_protocols SSLv3 TLSv1;
ssl_ciphers ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM;

server_name 10ninox.com;
}
``````

optional lines:

• `ssl_ciphers ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM;` means disables all weak ciphers
• `ssl_protocols SSLv3 TLSv1;` means enables SSLv3/TLSv1, but not SSLv2 which is weak and should no longer be used.

It’s better to test it first with

``````# service nginx configtest
``````

If pass,

``````# service nginx restart
``````

=)

• ## Firefox crashes XFCE

The more I use Ubuntu, the more I hate Unity. However, if you are going to simply install `xfce` like

`\$ sudo apt-get install xubuntu-desktop`

You will get xfce desktop environment easily; one thing I found is opening Firefox will end up freeze your system. After googling, the easiest solution I found is to delete .macromedia, done!

`\$ rm -rvf ~/.macromedia`

It just works.

• ## Django Tastypie filters

Tastypie is a pretty good REST interface under Django. One thing everyone wants from it is filtering. Tastypie provides a simple one through class Meta for ModelResource

```class Meta:
filtering = {
'fieldname': ALL
}```

As of now, we could passing GET parameters just like you do on model filter.

`http://localhost:8000/api/v1/yyyy/?format=json&fieldname__contains=queryword`

However, it sucks having tons of filters while you can do just one query word like

`http://localhost:8000/api/v1/yyyy/?format=json&q=queryword`

Basicly, filters in ModelResource works by going through `build_filters` then `apply_filters`. With the idea above, we need to override something in ModelResource. It's `build_filters(self, filters=None)`.

```def build_filters(self, filters=None):
if filters is None:
filters = {}
orm_filters = super(YyyyResource, self).build_filters(filters)

if 'q' in filters:
query = filters['q']
orm_filters['fieldname1__contains'] = filters['q']
orm_filters['fieldname2__contains'] = filters['q']
return orm_filters
```

By the way, it's AND filtering; if we want OR filtering, we will need to get much more complicated that just simple filter. Q is the answer, but in order to use it, we need to override `apply_filters(self, request, applicable_filters)` as well. The easiest thing is like following:-

```def apply_filters(self, request, applicable_filters):
base_object_list = super(YyyyResource, self).apply_filters(request, applicable_filters)
if 'q' in filters:
return base_object_list.filter(
Q(fieldname1__contains=filters['q']) |
Q(fieldname2__contains=filters['q']))
return base_object_list
```

There you go. It's exactly what we do in regular Django. Not to mention `apply_filters` which has request that contains `user` too.