-
A timestamp (in UTC or any other timezone)
-
A target timezone
The service responds with the equivalent timestamp in the target timezone.
-
Proto Definition: Define a .proto file with:
-
A ConvertTimeRequest message containing the timestamp and target timezone.
-
A ConvertTimeResponse message containing the converted timestamp.
-
A TimeZoneConverter service with one method, ConvertTime.
-
-
Server Implementation: Implement the TimeZoneConverter service in Golang:
-
Use the time and github.com/rickar/cal libraries for timezone conversions.
-
Handle basic errors (e.g., invalid timezones).
-
-
Client Implementation: Write a simple Golang client that:
-
Accepts input for timestamp and timezone via command line or hardcoded values.
-
Calls the gRPC server and prints the converted timestamp.
-
-
Parsing the Time:
-
The input time (2024-12-04T15:00:00Z) is in UTC, so it’s parsed using time.Parse with the time.RFC3339 layout.
-
The result is a time.Time object in the UTC time zone.
-
-
Loading the Target Time Zone:
- Use time.LoadLocation with the IANA time zone name (e.g., America/New_York).
-
Converting Time:
- The In(location) method converts the time to the desired time zone.
-
Output:
- Print both the original UTC time and the converted time for verification.
cd java.time.zone.converter.microservice
./mvnw testcd java.time.zone.converter.microservice
./mvnw exec:javaThe service port (8080) is for gRPC traffic. JDK Mission Control connects through JMX, so expose a separate JMX port (for example, 9010).
cd java.time.zone.converter.microservice
./mvnw exec:java \
-Dexec.jvmArgs="-Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=9010 -Dcom.sun.management.jmxremote.rmi.port=9010 -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=127.0.0.1"Then in Java Mission Control:
- Open JMC and look for the running local JVM in the JVM Browser.
- If it does not appear automatically, create a JMX connection to
127.0.0.1:9010. - Use the Overview, Memory, Threads, and Flight Recorder views to monitor behavior.
If you run the service in Docker, publish both ports, e.g. -p 8080:8080 -p 9010:9010, and ensure java.rmi.server.hostname is reachable from JMC.
Use the included script to generate concurrent gRPC requests and create visible load in Java Mission Control.
cd java.time.zone.converter.microservice
./simulate_traffic.shOptional tuning (defaults shown):
DURATION_SECONDS=300: longer run for sustained high traffic.CONCURRENCY=128: requests fired in parallel per cycle.TZ_MODE=multi: randomizes timezones to simulate globally distributed traffic (singleuses one timezone).TZ_POOL=...: comma-separated IANA timezone list used whenTZ_MODE=multi.GRPCURL_MAX_TIME=2: per-request timeout (seconds) to prevent hung clients under extreme load.TARGET_TZ=America/New_York: timezone value sent in requests.HOST=localhost:8080: service endpoint.
Examples:
cd java.time.zone.converter.microservice
DURATION_SECONDS=600 CONCURRENCY=192 TZ_MODE=multi ./simulate_traffic.shcd java.time.zone.converter.microservice
# Spike test: very high parallelism for a short window
DURATION_SECONDS=120 CONCURRENCY=512 GRPCURL_MAX_TIME=1 TZ_MODE=multi ./simulate_traffic.shcd java.time.zone.converter.microservice
# Soak test: lower but sustained load
DURATION_SECONDS=3600 CONCURRENCY=96 GRPCURL_MAX_TIME=3 TZ_MODE=multi ./simulate_traffic.shUse this helper script to print an ASCII graph of simulated requests-per-second (RPS) patterns.
cd java.time.zone.converter.microservice
./simulate_traffic_graph.shProfiles:
PROFILE=steady: mostly flat with light oscillation.PROFILE=burst: periodic short high-traffic bursts.PROFILE=spike: a few sharp spikes over baseline.PROFILE=soak: gradual ramp and long plateau.
Examples:
PROFILE=spike DURATION_SECONDS=300 STEP_SECONDS=5 BASE_RPS=1000 PEAK_RPS=12000 ./simulate_traffic_graph.shPROFILE=soak DURATION_SECONDS=1800 STEP_SECONDS=10 BASE_RPS=800 PEAK_RPS=8000 ./simulate_traffic_graph.shgrpcurl -plaintext \
-import-path ./java.time.zone.converter.microservice/proto \
-proto api.proto \
-d '{"timestamp": "2024-12-04T15:00:00Z", "target_timezone": "America/New_York"}' \
localhost:8080 \
timezone.TimeZoneConverter/ConvertTime-import-path ./java.time.zone.converter.microservice/proto: Specifies the proto directory for the Java service copy.
-proto api.proto: Specifies the .proto file that contains the service definition.
-d: Specifies the JSON payload, as in the previous example.
localhost:8080: Replace with your actual server address.
timezone.TimeZoneConverter/ConvertTime: Specifies the full service and method name, as per your .proto file.