| 
									
										
										
										
											2018-11-07 02:19:42 +08:00
										 |  |  | // Copyright 2018 The Prometheus Authors
 | 
					
						
							|  |  |  | // Licensed under the Apache License, Version 2.0 (the "License");
 | 
					
						
							|  |  |  | // you may not use this file except in compliance with the License.
 | 
					
						
							|  |  |  | // You may obtain a copy of the License at
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // http://www.apache.org/licenses/LICENSE-2.0
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Unless required by applicable law or agreed to in writing, software
 | 
					
						
							|  |  |  | // distributed under the License is distributed on an "AS IS" BASIS,
 | 
					
						
							|  |  |  | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
					
						
							|  |  |  | // See the License for the specific language governing permissions and
 | 
					
						
							|  |  |  | // limitations under the License.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-22 18:52:02 +08:00
										 |  |  | package tsdb | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2020-05-06 23:30:00 +08:00
										 |  |  | 	"io/ioutil" | 
					
						
							|  |  |  | 	"os" | 
					
						
							| 
									
										
										
										
											2018-10-22 18:52:02 +08:00
										 |  |  | 	"strconv" | 
					
						
							|  |  |  | 	"testing" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-30 15:45:42 +08:00
										 |  |  | 	"go.uber.org/atomic" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-19 03:53:33 +08:00
										 |  |  | 	"github.com/prometheus/prometheus/pkg/labels" | 
					
						
							| 
									
										
										
										
											2019-08-14 17:07:02 +08:00
										 |  |  | 	"github.com/prometheus/prometheus/util/testutil" | 
					
						
							| 
									
										
										
										
											2018-10-22 18:52:02 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func BenchmarkHeadStripeSeriesCreate(b *testing.B) { | 
					
						
							| 
									
										
										
										
											2020-05-06 23:30:00 +08:00
										 |  |  | 	chunkDir, err := ioutil.TempDir("", "chunk_dir") | 
					
						
							|  |  |  | 	testutil.Ok(b, err) | 
					
						
							|  |  |  | 	defer func() { | 
					
						
							|  |  |  | 		testutil.Ok(b, os.RemoveAll(chunkDir)) | 
					
						
							|  |  |  | 	}() | 
					
						
							| 
									
										
										
										
											2018-10-22 18:52:02 +08:00
										 |  |  | 	// Put a series, select it. GC it and then access it.
 | 
					
						
							| 
									
										
										
										
											2020-05-20 21:22:08 +08:00
										 |  |  | 	h, err := NewHead(nil, nil, nil, 1000, chunkDir, nil, DefaultStripeSize, nil) | 
					
						
							| 
									
										
										
										
											2018-10-22 18:52:02 +08:00
										 |  |  | 	testutil.Ok(b, err) | 
					
						
							|  |  |  | 	defer h.Close() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for i := 0; i < b.N; i++ { | 
					
						
							|  |  |  | 		h.getOrCreate(uint64(i), labels.FromStrings("a", strconv.Itoa(i))) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func BenchmarkHeadStripeSeriesCreateParallel(b *testing.B) { | 
					
						
							| 
									
										
										
										
											2020-05-06 23:30:00 +08:00
										 |  |  | 	chunkDir, err := ioutil.TempDir("", "chunk_dir") | 
					
						
							|  |  |  | 	testutil.Ok(b, err) | 
					
						
							|  |  |  | 	defer func() { | 
					
						
							|  |  |  | 		testutil.Ok(b, os.RemoveAll(chunkDir)) | 
					
						
							|  |  |  | 	}() | 
					
						
							| 
									
										
										
										
											2018-10-22 18:52:02 +08:00
										 |  |  | 	// Put a series, select it. GC it and then access it.
 | 
					
						
							| 
									
										
										
										
											2020-05-20 21:22:08 +08:00
										 |  |  | 	h, err := NewHead(nil, nil, nil, 1000, chunkDir, nil, DefaultStripeSize, nil) | 
					
						
							| 
									
										
										
										
											2018-10-22 18:52:02 +08:00
										 |  |  | 	testutil.Ok(b, err) | 
					
						
							|  |  |  | 	defer h.Close() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-30 15:45:42 +08:00
										 |  |  | 	var count atomic.Int64 | 
					
						
							| 
									
										
										
										
											2018-10-22 18:52:02 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	b.RunParallel(func(pb *testing.PB) { | 
					
						
							|  |  |  | 		for pb.Next() { | 
					
						
							| 
									
										
										
										
											2020-07-30 15:45:42 +08:00
										 |  |  | 			i := count.Inc() | 
					
						
							| 
									
										
										
										
											2018-10-22 18:52:02 +08:00
										 |  |  | 			h.getOrCreate(uint64(i), labels.FromStrings("a", strconv.Itoa(int(i)))) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}) | 
					
						
							|  |  |  | } |