Skip to content

Commit

Permalink
Merge pull request Qitmeer#62 from forchain/master
Browse files Browse the repository at this point in the history
swap memory tutorial
  • Loading branch information
forchain authored Mar 23, 2021
2 parents 669a299 + c95c4e4 commit 7cc04e5
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 48 deletions.
65 changes: 19 additions & 46 deletions Document/content/JSON RPC API/getUtxo/_index.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,58 +32,31 @@ Returns information about an unspent transaction output
#### Request

```sh
curl -s -k -u test:test -X POST -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"getRawTransaction","params":["c259a4dfb7eaaae92ab246f14762541581671135cd6030ac29d8c34cf77e9f32",true],"id":1}' https://127.0.0.1:18131
curl -sku "test:test" -X POST -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"getUtxo","params": ["cfd933e4590a3cfbcf94e9220c77834fe8a869414c51e3bd0ce5af23592e80f9", 0],"id":1}' http://127.0.0.1:18131 | jq


```
#### Response
```json
{
"hex": "0100000001dc7d54db024a1ef06e38b85ab01af2d60043e3d36b5411691224c05dcf36f63c01000000ffffffff02659ca300000000001976a91406e2097d585337cdd10aefa09994b511127af0bb88acf0e8cd6f230200001976a914fe27c90d4ed4de3269c0bb9ae1d7639865e3bf2888ac00000000000000008015fc5e016b48304502210090910aa0190a6571319b0b638bfbb593582575703abdd4f1a7f0da2812cda7d102205dae6fee28396bfeb8f1b814884d8d03ab0dd9f30b171d906c24914ba2f85b1a012103cd4fa2ea2688ac9e0a62584635244f572d22c13730d5576722d6571aabfddca8",
"txid": "c259a4dfb7eaaae92ab246f14762541581671135cd6030ac29d8c34cf77e9f32",
"txhash": "9b603ba3b17fd8491749ac366a5064d8b7b70be02568e405406a9acd70e971a8",
"size": 235,
"version": 1,
"locktime": 0,
"timestamp": "2020-07-01T12:48:00+08:00",
"expire": 0,
"vin": [
{
"txid": "3cf636cf5dc024126911546bd3e34300d6f21ab05ab8386ef01e4a02db547ddc",
"vout": 1,
"sequence": 4294967295,
"scriptSig": {
"asm": "304502210090910aa0190a6571319b0b638bfbb593582575703abdd4f1a7f0da2812cda7d102205dae6fee28396bfeb8f1b814884d8d03ab0dd9f30b171d906c24914ba2f85b1a01 03cd4fa2ea2688ac9e0a62584635244f572d22c13730d5576722d6571aabfddca8",
"hex": "48304502210090910aa0190a6571319b0b638bfbb593582575703abdd4f1a7f0da2812cda7d102205dae6fee28396bfeb8f1b814884d8d03ab0dd9f30b171d906c24914ba2f85b1a012103cd4fa2ea2688ac9e0a62584635244f572d22c13730d5576722d6571aabfddca8"
}
}
],
"vout": [
{
"amount": 10722405,
"scriptPubKey": {
"asm": "OP_DUP OP_HASH160 06e2097d585337cdd10aefa09994b511127af0bb OP_EQUALVERIFY OP_CHECKSIG",
"hex": "76a91406e2097d585337cdd10aefa09994b511127af0bb88ac",
"reqSigs": 1,
"type": "pubkeyhash",
"addresses": [
"TmPaUYQuUtfCysrYVHc4AdhpVHxw7EskHTP"
]
}
"jsonrpc": "2.0",
"id": 1,
"result": {
"bestblock": "6161b884e8ceaab14f23906a6ad3b86598dfaecbd805507ae4af302b85a95b10",
"confirmations": 143935,
"amount": 0.999326,
"scriptPubKey": {
"asm": "OP_DUP OP_HASH160 844d0a82845bccd469afc5cb78d8ffaa3142edea OP_EQUALVERIFY OP_CHECKSIG",
"hex": "76a914844d0a82845bccd469afc5cb78d8ffaa3142edea88ac",
"reqSigs": 1,
"type": "pubkeyhash",
"addresses": [
"Tmb1dCAB8ixNC6d2VtdCYZuhXBVPbnRVi7y"
]
},
{
"amount": 2351222876400,
"scriptPubKey": {
"asm": "OP_DUP OP_HASH160 fe27c90d4ed4de3269c0bb9ae1d7639865e3bf28 OP_EQUALVERIFY OP_CHECKSIG",
"hex": "76a914fe27c90d4ed4de3269c0bb9ae1d7639865e3bf2888ac",
"reqSigs": 1,
"type": "pubkeyhash",
"addresses": [
"Tmn7vzzSrvAPNLtwpD5YjiWwVUBD74Hjdww"
]
}
}
],
"confirmations": 0
"version": 0,
"coinbase": false
}
}

```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
title: Qitmeer Token Issurance
title: Qitmeer Token Issuance
weight: 5
#pre: "<b>1. </b>"
# chapter: true
---

Qitmeer assets issurance componet, OP_TOKEN, is based on UTXO (Unspent Transaction Output) transaction model, to support massive islamic economic liquidity. OP_TOKEN ensures assets backed by native currency and requires authority-owned licenses to publish assets, which is designed for sharia consideration scenarios.
Qitmeer assets issuance component, OP_TOKEN, is based on UTXO (Unspent Transaction Output) transaction model, to support massive islamic economic liquidity. OP_TOKEN ensures assets backed by native currency and requires authority-owned licenses to publish assets, prevented from scammer assets.
2 changes: 2 additions & 0 deletions Document/content/tutorials/_index.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ weight: 3
- [Qitmeer Wallet Rpc Guide](./qitmeer-wallet-rpc)

- [Qitmeer JS Guide](./qitmeer-js)

- [Mount Swap Memory](./swap-memory)
78 changes: 78 additions & 0 deletions Document/content/tutorials/swap-memory/_index.en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
title: Swap Memory
weight: 1
#pre: "<b>1. </b>"
# chapter: true
---

This tutorial instructs qitmeer node maintainers to mount swap memory to solve the Out of Memory problem.

## Problem Description
Qitmeer's recommended memory perquisite is 2GB, 1 GB at minimum. Even though memory has satisfied the recommended requirement, it is still possible that Qitmeer gets killed by system due to peak usage of memory, called Out of Memory exception.

```sh
2021-03-23|07:45:22.110 [INFO ] Processed 211 blocks in the last 10s (217 transactions, order 283091, 2020-09-27 15:05:08 +0800 CST) module=blkmanager
[1] 196072 killed ./build/bin/qitmeer

```

You may confirm this exception by the command:

> Note: assume OS is Ubuntu
```sh
dmesg -T| grep -E -i -B100 'killed process'
```
If you find similar output as follows, then that maybe the case
```sh
[Tue Mar 9 11:34:26 2021] Out of memory: Killed process 140587 (qitmeer) total-vm:1403144kB,
anon-rss:675828kB, file-rss:0kB, shmem-rss:0kB, UID:1001 pgtables:1532kB oom_score_adj:0
```

## Solution
### What is Swap Memory
OS could transfer inactive memory into hard disk to make room for active processes, called memory swapping. Although this mechanism would reduce the overall performance of machines due to high swapping cost between physical memory and virtual memory (hard disk), it brings stronger stability.

## How to mount swap memory
> Note: Ensure you have root permission
1. create folder for swap file

```bash
root@Qit:/home/tony$ cd /
root@Qit:/$ mkdir swap
root@Qit:/$ cd swap/
```

2. create a 2GB swap file
```bash
root@Qit:/swap$ dd if=/dev/zero of=SWAPFILE bs=1024 count=2097152
2097152+0 records in
2097152+0 records out
2147483648 bytes (2.1 GB, 2.0 GiB) copied, 14.838 s, 145 MB/s
```

3. convert into swap format
```sh
root@Qit:/swap$ mkswap SWAPFILE 2097152
mkswap: SWAPFILE: insecure permissions 0644, 0600 suggested.
Setting up swapspace version 1, size = 2 GiB (2147479552 bytes)
no label, UUID=06ee7e99-ab8f-4378-b0d0-3f5477bd1090
```

4. format swap file
```sh
root@Qit:/swap$ swapon SWAPFILE
swapon: /swap/SWAPFILE: insecure permissions 0644, 0600 suggested.
```
check swap file usage
```sh
root@Qit:/swap$ free
total used free shared buff/cache available
Mem: 980192 271480 63400 2676 645312 545572
Swap: 2097148 0 2097148
```
5. auto mount swap file on booting
```sh
root@Qit:~$ echo "/swap/SWAPFILE swap swap defaults 0 0" >> /etc/fstab
```

0 comments on commit 7cc04e5

Please sign in to comment.