Skip to content

Commit

Permalink
Update code for ponyc 0.28.0
Browse files Browse the repository at this point in the history
  - updates PosixDate format calls to be partial and wrapped in
    try blocks
  • Loading branch information
JONBRWN committed Apr 2, 2019
1 parent 69bde55 commit c767e46
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
25 changes: 18 additions & 7 deletions examples/performance/main.pony
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,9 @@ actor C is KafkaConsumer
else
"\n"
end

@printf[I32]((Date(Time.seconds()).format("%Y-%m-%d %H:%M:%S") + ": Consuming data. Waiting for: " + num_msgs.string() + " messages." + latency_message).cstring())
try
@printf[I32]((PosixDate(Time.seconds()).format("%Y-%m-%d %H:%M:%S")? + ": Consuming data. Waiting for: " + num_msgs.string() + " messages." + latency_message).cstring())
end

// behavior kafka calls for each message received that should be sent to this
// actor
Expand All @@ -272,14 +273,18 @@ actor C is KafkaConsumer

ifdef debug then
if (num_msgs_consumed % 100000) == 0 then
@printf[I32]((Date(Time.seconds()).format("%Y-%m-%d %H:%M:%S") + ": Received " + num_msgs_consumed.string() + " messages so far\n").cstring())
try
@printf[I32]((PosixDate(Time.seconds()).format("%Y-%m-%d %H:%M:%S")? + ": Received " + num_msgs_consumed.string() + " messages so far\n").cstring())
end
end
end

if num_msgs_consumed == num_msgs then
let end_ts = Time.nanos()
let time_taken = (end_ts - start_ts).f64()/1_000_000_000.0
@printf[I32]((Date(Time.seconds()).format("%Y-%m-%d %H:%M:%S") + ": Received " + num_msgs_consumed.string() + " messages as requested. Time taken: " + time_taken.string() + " seconds. Throughput: " + (num_msgs_consumed.f64()/time_taken.f64()).string() + "/sec.\n").cstring())
try
@printf[I32]((PosixDate(Time.seconds()).format("%Y-%m-%d %H:%M:%S")? + ": Received " + num_msgs_consumed.string() + " messages as requested. Time taken: " + time_taken.string() + " seconds. Throughput: " + (num_msgs_consumed.f64()/time_taken.f64()).string() + "/sec.\n").cstring())
end

if measure_latency then
// TODO: Add in logic to print latency histogram
Expand Down Expand Up @@ -362,7 +367,9 @@ actor P is KafkaProducer
end

be kafka_producer_ready(client: KafkaClient) =>
@printf[I32]((Date(Time.seconds()).format("%Y-%m-%d %H:%M:%S") + ": Producing data\n").cstring())
try
@printf[I32]((PosixDate(Time.seconds()).format("%Y-%m-%d %H:%M:%S")? + ": Producing data\n").cstring())
end
start_ts = Time.nanos()
produce_data()

Expand All @@ -383,7 +390,9 @@ actor P is KafkaProducer
if num_msgs_produced_acked == num_msgs then
let end_ts = Time.nanos()
let time_taken = (end_ts - start_ts).f64()/1_000_000_000.0
@printf[I32]((Date(Time.seconds()).format("%Y-%m-%d %H:%M:%S") + ": Received acks for all " + num_msgs_produced_acked.string() + " messages produced. num_errors: " + num_errors.string() + ". Time taken: " + time_taken.string() + " seconds. Throughput: " + (num_msgs_produced_acked.f64()/time_taken.f64()).string() + "/sec.\n").cstring())
try
@printf[I32]((PosixDate(Time.seconds()).format("%Y-%m-%d %H:%M:%S")? + ": Received acks for all " + num_msgs_produced_acked.string() + " messages produced. num_errors: " + num_errors.string() + ". Time taken: " + time_taken.string() + " seconds. Throughput: " + (num_msgs_produced_acked.f64()/time_taken.f64()).string() + "/sec.\n").cstring())
end
@printf[I32]("Shutting down\n".cstring())
_kc.dispose()
end
Expand Down Expand Up @@ -453,6 +462,8 @@ actor P is KafkaProducer
_kc.dispose()
end
else
@printf[I32]((Date(Time.seconds()).format("%Y-%m-%d %H:%M:%S") + ": Done producing data\n").cstring())
try
@printf[I32]((PosixDate(Time.seconds()).format("%Y-%m-%d %H:%M:%S")? + ": Done producing data\n").cstring())
end
end

10 changes: 7 additions & 3 deletions pony-kafka/customlogger/logger.pony
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,15 @@ class val Logger[A]
level() >= _level()

fun log(level: LogLevel, value: A,
date: String = PosixDate(Time.seconds()).format("%Y-%m-%d %H:%M:%S"),
loc: SourceLoc = __loc): Bool
=>
_out.print(_formatter(level, _f(consume value), _verbose, date, loc))
true
try
let date = PosixDate(Time.seconds()).format("%Y-%m-%d %H:%M:%S")?
_out.print(_formatter(level, _f(consume value), _verbose, date, loc))
true
else
false
end

primitive StringLogger
fun apply(level: LogLevel,
Expand Down

0 comments on commit c767e46

Please sign in to comment.