Created
August 13, 2010 02:51
-
-
Save alphazero/522177 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Copyright 2010 Joubin Houshyar | |
| * | |
| * 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. | |
| */ | |
| package org.jredis.ri.alphazero.bench; | |
| import java.io.Serializable; | |
| import org.jredis.JRedis; | |
| import org.jredis.RedisException; | |
| import org.jredis.bench.Util.Timer; | |
| import org.jredis.connector.ConnectionSpec; | |
| import org.jredis.ri.alphazero.JRedisClient; | |
| import org.jredis.ri.alphazero.connection.DefaultConnectionSpec; | |
| /** | |
| * [TODO: document me!] | |
| * | |
| * @author joubin ([email protected]) | |
| * @date Aug 12, 2010 | |
| * | |
| */ | |
| public class JRedisClientContinuousOpBenchmark { | |
| public static void main (String[] args) { | |
| new JRedisClientContinuousOpBenchmark().run(); | |
| } | |
| public void run() { | |
| int reps = 1000; | |
| ConnectionSpec spec = DefaultConnectionSpec.newSpec() | |
| .setCredentials("jredis".getBytes()) | |
| .setDatabase(13); // << we will flush this db | |
| JRedis jredis = new JRedisClient(spec); | |
| try { | |
| jredis.flushdb(); | |
| for(;;) benchOp(jredis, reps); | |
| } | |
| catch (RedisException e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| private void benchOp(JRedis jredis, int reps){ | |
| Timer timer = Timer.startNewTimer(); | |
| String key = "baby!"; | |
| try { | |
| for(int i=0; i<reps; i++) { | |
| Woof woof = new Woof(); | |
| jredis.set(key+woof.timestamp, woof); | |
| } | |
| } | |
| catch (RedisException e) { | |
| e.printStackTrace(); | |
| } | |
| finally { | |
| timer.mark(); | |
| System.out.format("delta: %d - keys: %09d \n", timer.deltaAtMark(), keyCnt(jredis)); | |
| } | |
| } | |
| private long keyCnt (JRedis jRedis) { | |
| try { | |
| return jRedis.dbsize(); | |
| } | |
| catch (RedisException e) { | |
| throw new RuntimeException("", e); | |
| } | |
| } | |
| @SuppressWarnings("serial") | |
| public static class Woof implements Serializable { | |
| public final long timestamp = System.currentTimeMillis(); | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Btw, the above output is with append log on. With default settings, the performance is considerably better (and o/c still O(1)):
elta: 117 - keys: 000002447
delta: 118 - keys: 000002566
delta: 119 - keys: 000002686
delta: 119 - keys: 000002805
delta: 112 - keys: 000002917
delta: 127 - keys: 000003041
delta: 117 - keys: 000003158
delta: 115 - keys: 000003273
delta: 116 - keys: 000003389
delta: 115 - keys: 000003503
delta: 113 - keys: 000003617
delta: 113 - keys: 000003730
delta: 113 - keys: 000003844
delta: 131 - keys: 000003974
...
delta: 115 - keys: 000024042
delta: 115 - keys: 000024157
delta: 115 - keys: 000024270
delta: 113 - keys: 000024384
delta: 116 - keys: 000024501
delta: 116 - keys: 000024617
delta: 117 - keys: 000024733
...
delta: 117 - keys: 000042733
delta: 115 - keys: 000042847
delta: 117 - keys: 000042964
delta: 119 - keys: 000043081
delta: 115 - keys: 000043197
delta: 118 - keys: 000043315
delta: 114 - keys: 000043429
delta: 120 - keys: 000043547
delta: 118 - keys: 000043666
delta: 118 - keys: 000043784
...
elta: 119 - keys: 000091534
delta: 115 - keys: 000091649
delta: 115 - keys: 000091765
delta: 116 - keys: 000091880
delta: 115 - keys: 000091996
delta: 117 - keys: 000092111
delta: 117 - keys: 000092228
delta: 114 - keys: 000092343
delta: 117 - keys: 000092459
delta: 115 - keys: 000092574
...
delta: 116 - keys: 000112310
delta: 113 - keys: 000112424
delta: 114 - keys: 000112538
delta: 115 - keys: 000112653
delta: 114 - keys: 000112767
delta: 116 - keys: 000112884
...
delta: 119 - keys: 000132149
delta: 119 - keys: 000132268
delta: 114 - keys: 000132382
delta: 116 - keys: 000132499
delta: 115 - keys: 000132615