MCQs on Deployment and Performance Optimization | Go

In Go, building and deploying efficient binaries, profiling with pprof, and optimizing memory and CPU usage are critical for building high-performance applications. This guide explores these essential topics in Go development.


1. Building and Deploying Go Binaries

  1. What is the command to build a Go binary?
    a) go build
    b) go run
    c) go install
    d) go compile
  2. How do you build a Go binary for a specific OS and architecture?
    a) go build -o binary_name
    b) go build -os=linux -arch=amd64
    c) go target -os=linux
    d) go build –platform=linux-amd64
  3. What command is used to install a Go package?
    a) go install
    b) go build
    c) go get
    d) go download
  4. Which file extension is used for Go binaries on Linux?
    a) .go
    b) .exe
    c) .bin
    d) No extension
  5. How do you create a statically linked Go binary?
    a) go build -static
    b) go build -ldflags “-extldflags ‘-static'”
    c) go build -static-link
    d) go static build
  6. Which command can be used to cross-compile a Go binary for different platforms?
    a) go crosscompile
    b) go build -platform
    c) GOOS=linux GOARCH=amd64 go build
    d) go build –cross
  7. How do you compile Go code with debugging symbols included?
    a) go build -debug
    b) go build -ldflags “-w -s”
    c) go build -v
    d) go build -d
  8. Which environment variables are used to target a specific operating system and architecture in Go?
    a) GOOS and GOARCH
    b) GO_PLATFORM and GO_ARCH
    c) TARGET_OS and TARGET_ARCH
    d) GO_TARGET and GO_ENV
  9. What is the purpose of the go install command?
    a) It installs the Go package dependencies
    b) It compiles and installs the Go binary into the workspace
    c) It builds the package but does not install
    d) It installs a Go package globally
  10. How can you strip debugging information from a Go binary?
    a) go build -ldflags “-s -w”
    b) go build -strip-debug
    c) go build -o binary -strip
    d) go strip-debug

2. Profiling with pprof

  1. Which package is used for profiling in Go?
    a) pprof
    b) profiling
    c) go-profile
    d) benchmark
  2. How do you import the pprof package in a Go program?
    a) import “net/pprof”
    b) import “github.com/pprof”
    c) import “go/pprof”
    d) import “net/http/pprof”
  3. How do you start profiling CPU usage in a Go program?
    a) pprof.StartCPUProfile()
    b) pprof.Start()
    c) cpuProfile.Start()
    d) StartProfile(pprof)
  4. What is the default port used by the pprof HTTP server in Go?
    a) 8000
    b) 9090
    c) 6060
    d) 8080
  5. How do you stop the CPU profiling in Go?
    a) pprof.StopCPUProfile()
    b) pprof.EndProfile()
    c) cpuProfile.Stop()
    d) StopProfile(pprof)
  6. What command is used to generate a CPU profile using pprof?
    a) go tool pprof -cpu profile.prof
    b) go pprof generate cpu_profile
    c) go tool pprof -text
    d) go tool pprof -cpu <profile_file>
  7. Which command can be used to display the heap profile?
    a) pprof display heap
    b) go tool pprof -heap
    c) go tool pprof -mem
    d) go tool pprof -heap_profile
  8. How can you view the heap profile of a Go program?
    a) go run -memprofile=heap.prof
    b) go tool pprof heap
    c) curl http://localhost:6060/debug/pprof/heap
    d) go profile -heap
  9. Which of the following is the correct method to add pprof to your application?
    a) Import net/http/pprof
    b) Import pprof/http
    c) Import go/pprof
    d) Import pprof
  10. What is the purpose of the pprof tool in Go?
    a) It helps monitor memory usage
    b) It generates binary executables
    c) It provides performance profiling tools
    d) It runs unit tests

3. Memory and CPU Optimization Techniques

  1. Which technique helps optimize memory usage in Go?
    a) Garbage Collection
    b) Memory pools
    c) Caching
    d) All of the above
  2. What is the effect of enabling Go’s garbage collection?
    a) It automatically frees up unused memory
    b) It reduces memory usage significantly
    c) It increases memory usage
    d) It prevents memory leaks
  3. Which of the following can help reduce memory allocations in Go?
    a) Using buffered channels
    b) Using slices and arrays efficiently
    c) Avoiding unnecessary copies of data
    d) All of the above
  4. What is the role of the sync.Pool type in Go?
    a) It is used to optimize memory usage by reusing objects
    b) It handles garbage collection automatically
    c) It helps in concurrent memory management
    d) It reduces the CPU usage
  5. Which of the following is a common CPU optimization technique in Go?
    a) Parallel processing
    b) Using memory-mapped files
    c) Implementing caching algorithms
    d) All of the above
  6. How does the Go runtime optimize CPU usage during concurrent execution?
    a) By using goroutines
    b) By using system threads
    c) By using CPU affinity
    d) By distributing workloads across multiple cores
  7. What command can be used to view the CPU usage profile in Go?
    a) go tool pprof -cpu
    b) go tool pprof cpu.profile
    c) go cpu-profile
    d) pprof -cpu-profile
  8. What is a good strategy for reducing memory usage in Go?
    a) Minimizing the number of allocations
    b) Reducing the number of goroutines
    c) Keeping data in a memory-mapped file
    d) Both a and b
  9. Which is a best practice for managing memory in Go?
    a) Use value types whenever possible
    b) Use pointers for large objects
    c) Avoid creating large slices in loops
    d) All of the above
  10. How can you profile CPU performance in Go?
    a) Using go tool pprof
    b) Using pprof.CPUProfile()
    c) Using the go profiler
    d) Using cpu.profiler

Answers Table

QNoAnswer (Option with Text)
1a) go build
2b) go build -os=linux -arch=amd64
3c) go get
4d) No extension
5b) go build -ldflags “-extldflags ‘-static'”
6c) GOOS=linux GOARCH=amd64 go build
7b) go build -ldflags “-w -s”
8a) GOOS and GOARCH
9b) It compiles and installs the Go binary into the workspace
10a) go build -ldflags “-s -w”
11a) pprof
12d) import “net/http/pprof”
13a) pprof.StartCPUProfile()
14c) 6060
15a) pprof.StopCPUProfile()
16a) go tool pprof -cpu profile.prof
17b) go tool pprof -heap
18c) curl http://localhost:6060/debug/pprof/heap
19a) Import net/http/pprof
20c) It provides performance profiling tools
21d) All of the above
22a) It automatically frees up unused memory
23d) All of the above
24a) It is used to optimize memory usage by reusing objects
25d) All of the above
26a) By using goroutines
27b) go tool pprof cpu.profile
28d) Both a and b
29d) All of the above
30a) Using go tool pprof

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top