You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+12-10
Original file line number
Diff line number
Diff line change
@@ -20,8 +20,8 @@ Thanks to this small library, you can create relatively simple code without the
20
20
Normally a web application is using following pattern to modify data in the database:
21
21
22
22
1.**Load resource** from database. Resource is some portion of data
23
-
such as record, document etc. Lock the entire resource pessimistically
24
-
or optimistically (by reading version number).
23
+
such as set of records from relational database, document from Document-oriented database or value from KV store.
24
+
Lock the entire resource pessimistically or optimistically (by reading version number).
25
25
2.**Apply change** to data
26
26
3.**Save resource** to database. Release the pessimistic lock. Or run
27
27
atomic update with version check (optimistic lock).
@@ -37,7 +37,7 @@ Because a single resource is loaded and saved thousands of times per second
37
37
we can instead:
38
38
39
39
1. Load the resource **once** (let's say once per second)
40
-
2. Execute all the requests from this period of time on an already loaded resource. Run them all sequentially.
40
+
2. Execute all the requests from this period of time on an already loaded resource. Run them all sequentially to keep things simple and data consistent.
41
41
3. Save the resource and send responses to all clients if data was stored successfully.
42
42
43
43
Such solution could improve the performance by a factor of 1000. And resource is still stored in a consistent state.
// Here you put the code which will executed sequentially inside batch
64
65
})
@@ -72,18 +73,19 @@ For real-life example see [example web application](_example).
72
73
# Add batch to your Go module:
73
74
go get github.com/elgopher/batch
74
75
```
75
-
Please note that at least **Go 1.18** is required.
76
+
Please note that at least **Go 1.18** is required. The package is using generics, which was added in 1.18.
76
77
77
78
## Scaling out
78
79
79
-
Single Go http server is able to handle up to tens of thousands of requests per second on a commodity hardware. This is a lot, but very often you also need:
80
+
Single Go http server is able to handle up to tens of thousands of requests per second on a commodity hardware.
81
+
This is a lot, but very often you also need:
80
82
81
83
* high availability (if one server goes down you want other to handle the traffic)
82
-
* you want to handle hundredthousands or millions of requests per second
84
+
* you want to handle hundred-thousands or millions of requests per second
83
85
84
86
For both cases you need to deploy **multiple servers** and put a **load balancer** in front of them.
85
87
Please note though, that you have to carefully configure the load balancing algorithm.
86
-
Round-robin is not an option here, because sooner or later you will have problems with locking
88
+
_Round-robin_ is not an option here, because sooner or later you will have problems with locking
87
89
(multiple server instances will run batches on the same resource).
88
90
Ideal solution is to route requests based on parameters or URL.
89
91
For example some http parameter could be a resource key. You can instruct load balancer
0 commit comments