Is file.rename() atomic?
void rename(in char[] from, in char[] to); Rename file from to to. If the target file exists, it is overwritten. Throws: FileException on error. Just wanted to know if this operation is atomic? or does it depend on the underlying file system? In short, in the file nanoseconds/milliseconds that this operation is occurring is it possible for someone else to be reading the same file and get a dirty read (i.e. with only half of the contents overriden, etc)? Thanks
Re: Newbie Question: SOAP Module
is there any particular reason you are forced to use SOAP? It is more or less an obsolete and generally frowned upon approach. if you were willing to adopt REST, vibe.d seems to have some nice functionality for creating REST APIs. Look at the 'Routing' section here: http://vibed.org/docs#http-server-config
Re: Reflections on Serialization APIs in D
The reason I like Thrift is that it is backwards and forwards compatible. Assuming in your schema you keep defining new fields as optional, old clients can read data from new producers as well as new clients can read data from old producers. Not too many binary serialization formats offer this type of flexibility to evolve your schema over time.
Re: Compiling an app to a single binary - possible?
It is possible to import an entire folder and subfolders of assets? (e.g. static HTML with all of its pieces, i.e. CSS, JSS. etc)
Re: Reflections on Serialization APIs in D
I have not used it in D, but we use Thrift in Java a lot and I've been very happy with it on many levels. it works really well in production. Since Thrift has D bindings as of recently, it may be worth your time to investigate.
Re: Compiling an app to a single binary - possible?
In this case is the content of ./public compiled directly into the executable (let's say the way all web resources are compiled into a Java WAR file), or does it have to be a separate folder on the filesystem, deployed alongside the main executable?
Compiling an app to a single binary - possible?
One of the nice features of Go is that when you compile an app, it pulls in ALL the dependencies (i.e. the full SDK + all libraries your app depends on) and generates a single binary (around 2 MB for a Hello World app). This is extremely useful for deployment purposes, since it is so straightforward to just copy the app to multiple servers without having to worry if every one of them has all the required dependencies installed / updated, etc. Does D offer something similar (maybe via some dmd switches)? For example, If I am creating a vibe.d app, would I need to deploy the vibe.d libraries separately with my app on all the servers in production? Thanks Jacek
Re: Compiling an app to a single binary - possible?
Thank you for the quick response, that is great news. Cheers Jacek
Re: What is the closest to ConcurrentHashMap and NavigableMap in Java?
On Friday, 15 November 2013 at 07:42:22 UTC, ilya-stromberg wrote: On Thursday, 14 November 2013 at 22:12:10 UTC, Jacek Furmankiewicz wrote: On Thursday, 14 November 2013 at 21:36:46 UTC, ilya-stromberg wrote: On Thursday, 14 November 2013 at 21:31:52 UTC, Jacek Furmankiewicz wrote: How often do you change the data? Probably, you should use `immutable` variables. Customer specific. It may change once a year. It may change multiple times per second for a while, then nothing again for weeks. Others may do mass loads of business rules, hence do mass changes every few hours. Next to impossible to predict. You can use `immutable` variables. It allows you to share the data without any synchronization. Like this: class MyData { int data1; string data2; //creates new object this(int data1, string data2) { this.data1 = data1; this.data2 = data2; } //modify the data immutable(MyData) editData(int i) const { //copy this object - we can't change immutable variables MyData dataCopy = new MyData(this.data1, this.data2) //modify the data copy dataCopy.data1 += i; //assume that `dataCopy` is immutable return cast(immutable(MyData)) dataCopy; } } shared myMap; //map implementation synchronized class MyMap { HashMap!(int, immutable(MyData)) map; void foo() { map[1] = new immutable MyData(1, data); } void bar() { map[1] = map[1].editData(5); } } //init map shared static this() { myMap = new MyMap(); } void main() { myMap.foo(); myMap.bar(); } So what happens when the write operation is doing map[1] = map[1].editData(5); and at the same time 50 threads are simultaneously reading the value in map[1]?. Is that reassignment operation thread safe? Or would I get corrupted reads with potentially a partially overriden value? Jacek
Re: What is the closest to ConcurrentHashMap and NavigableMap in Java?
So, if you add a read() method to MyMap for those threads, would that be synchronized as well? That is what we would not want due performance impact. How can you achieve lock-free reads with the synchronized MyMap approach?
Re: What is the closest to ConcurrentHashMap and NavigableMap in Java?
Yes, that is what they say in Go...but it doesn't scale either. :-) I had the exact same discussion on the Go forums a while back and the conclusion was basically the same...roll your own maps with RW locks: https://groups.google.com/forum/?fromgroups#!searchin/golang-nuts/furmankiewicz/golang-nuts/jjjvXG4HdUw/ffWytKQ7X9YJ But...at the end someone actually built lock-free data structures in Go out of this: https://github.com/zond/gotomic
Re: What is the closest to ConcurrentHashMap and NavigableMap in Java?
On Friday, 15 November 2013 at 17:46:41 UTC, Russel Winder wrote: The trend in the JVM-verse is very much if you use synchronized or an explicit lock, and you are not creating a core library data structure, you are doing it wrong. The background is that the whole purpose of a lock it to control concurrency and thus stop parallelism. Applications programmers should never have to use a lock. ConcurrentHashMap, and thread safe queues are two consequences of all this. True, concurrency in Java is really simple these days (especially with the Executors framework that Python 3 pretty much copies verbatim). taskPool looks like the closest equivalent in D that I could find.
Re: What is the closest to ConcurrentHashMap and NavigableMap in Java?
No, we didn't decide to migrate to D. Java is working out fine for us. I am however always interested in what is out there, 'cause you never know if there may not be a better solution. And from what I've seen so far I really like D in terms of pure language features. Go is cool too, but it has made some choices which to me are questionable (error codes instead of exceptions, lack of templates/generics). Coupled with vibe.d, dub, etc. I see some really interesting stuff going on in the D community that seems to have been greatly under the radar. Definitely plan to spend more time with D on my own, even if I cannot use it at work.
Re: What is the closest to ConcurrentHashMap and NavigableMap in Java?
if I recall from the initial Go discussion, the Go folks were saying that for close to realtime SLAs the goroutine/channel approach may have some scalability limits...which is why they started recommending the RW mutex approach in the end. Now, that was a few months ago, since then Go 1.1 (and soon 1.2) came out, so that may be a false statement at this time.
Re: What is the closest to ConcurrentHashMap and NavigableMap in Java?
Thank you Russell for the explanation. Always a chance to learn something new.
Re: What is the closest to ConcurrentHashMap and NavigableMap in Java?
Sohow does Facebook handle it with their new D code? No GC at all, explicit memory management?
Efficient string concatenation?
Since D strings are immutable (like in most other languages), string concatenation is usually pretty inefficient due to the need to create a new copy of the string every time. I presume string concatenation using the typical array syntax can be optimized by the compiler to do all of this in one shot, e..g string newString = string1 ~ string2 ~ string3; but what happens if I need to concatenante a large string in a loop? I tried looking through Phobos for a StringBuilder class (since that is the common solution in Java and C#), but did not find anything similar. What is the D way of doing efficient string concatenation (especially if it spans multiple statements, e.g. while in a loop)?
Re: Efficient string concatenation?
Thank you all. I am learning D by going through Ali Cehreli's otherwise excellent Programming in D PDF and he did not show this in his initial chapter on Strings.
OptionalT equivalent in D?
Many other languages are starting to frown on returning null values from methods (due to NullPointerException risks, etc) and wrapping them instead in an OptionalT like in Scala: http://blog.danielwellman.com/2008/03/using-scalas-op.html Google Guava for Java: (now rolled into the base JDK for Java 8): https://code.google.com/p/guava-libraries/wiki/UsingAndAvoidingNullExplained Is there a similar approach in D? Or maybe an equivalent is in a commonly used external library?
Re: OptionalT equivalent in D?
Thanks! std.typecons definitely looks like something I need to dig into.
Re: Efficient string concatenation?
Thanks for the book! I printed it, all 673 pages of it. Immense work you have there.
What is the closest to ConcurrentHashMap and NavigableMap in Java?
In our Java code, we make heavy use of ConcurrentHashMap for in-memory caches: http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ConcurrentHashMap.html We use it mostly for in-memory caches. A background thread wakes up every X seconds and resyncs the cache with whatever changes occurred in the DB. In the meantime, all the incoming requests can read from the same cache without any concurrency issues and excellent performance. All the major Java Map implementations also support the NavigableMap interface: http://docs.oracle.com/javase/7/docs/api/java/util/NavigableMap.html which allows you to get the key closest to the one you are looking for (either up or down). This is very useful when you have hierarchies of business rules that have effective date ranges and you are trying to find which rules is active on a particular day. I read up the chapter on associative arrays in D, but I do not see anything similar to this functionality in there. Could anyone point me to what would be the closest D equivalents (maybe in an external library if not part of Phobos) so we can playing around with them? Much appreciated Jacek
Re: What is the closest to ConcurrentHashMap and NavigableMap in Java?
So how do existing D applications (especially the high perf ones in let's say the financial sector) deal with having some part of the data in memory and keeping it in sync with the DB source? This must be a very common requirement for any app with realtime or close-to-realtime SLAs. is there a different idiom or approach in D?
Re: What is the closest to ConcurrentHashMap and NavigableMap in Java?
Thanks for the links. I looked at the dcollections docs, but none of their collections seem thread safe. The vibe.d I guess is because it is meant to be used from async I/O in a single thread...but once you add multi-threading to an app I am guessing it would not be usable.
Re: What is the closest to ConcurrentHashMap and NavigableMap in Java?
hashmap per thread is not an option. The cache may be a few GBs of data, there is no way we can duplicate that data per thread. Not to mention the start up time when we have to warm up the cache.
Re: What is the closest to ConcurrentHashMap and NavigableMap in Java?
On Thursday, 14 November 2013 at 21:36:46 UTC, ilya-stromberg wrote: On Thursday, 14 November 2013 at 21:31:52 UTC, Jacek Furmankiewicz wrote: How often do you change the data? Probably, you should use `immutable` variables. Customer specific. It may change once a year. It may change multiple times per second for a while, then nothing again for weeks. Others may do mass loads of business rules, hence do mass changes every few hours. Next to impossible to predict.
Re: What is the closest to ConcurrentHashMap and NavigableMap in Java?
On Thursday, 14 November 2013 at 21:39:53 UTC, bearophile wrote: Jacek Furmankiewicz: hashmap per thread is not an option. The cache may be a few GBs of data, there is no way we can duplicate that data per thread. But is the D garbage collector able to manage efficiently enough associative arrays of few gigabytes? You are not dealing with a GC nearly as efficient as the JavaVM one. Well, these are the types of questions I have as a Java veteran who is having a first look at D after the recent Facebook announcement. By now I have a decent idea of where most of the new languages (Go has same issues, for the most part) come up short when compared to Java's very mature SDK, so that is usually where I start probing first. Sorry :-(
Re: What is the closest to ConcurrentHashMap and NavigableMap in Java?
True. While looking a D, I am just trying to focus on the parts which I know would be a showstopper for us on day one...and this particular issue is it. I do like D a lot as well from what I've seen so far. Regarding the GC, I've seen some slides on DConf about other garbage collectors available. Is there any resource/tutorial that shows how you can swap out the default GC for those alternative implementations?
Errors running a vibe.d program using dub
Hi, first time D newbie here, so please forgive me. I am trying to write my first D program, namely a basic web server using vibe.d and dub. The code is the basic code on the vibe.d page: http://vibed.org/ After installing dub, I init a new project using it and followed the steps on how to add vibe.d as a dependency: http://vibed.org/docs#first-steps When I try to compile and run it using dub, I get: dub Checking dependencies in '/home/jacekf/tmp/webd' Building configuration application, build type debug Compiling... Linking... /usr/bin/ld: cannot find -levent /usr/bin/ld: cannot find -levent_pthreads collect2: error: ld returned 1 exit status --- errorlevel 1 Error: Link command failed with exit code 1 Run 'dub help' for usage information. I made sure on my Ubuntu (64-bit) box, I have libevent installed (both the libevent-1.4.2 and libevent-2.0.5 packages, not sure which one it needs), as well as libevent-pthreads-2.0-5. Still no luck, I am obviously missing something very basic. Thank you for any help in helping me with my first D program. Cheers Jacek
Re: Errors running a vibe.d program using dub
Thank you so much, I missed that page. I am running now, much appreciated.